哪些语言提供对象文字的使用?

发布于 2024-10-10 00:40:56 字数 213 浏览 2 评论 0原文

哪些语言提供对象文字的使用? (或者你可以用什么语言轻松模拟它们?)你能给出一个代码示例吗?

从明显的 javascript 片段开始:

var someObj = {
    someProperty: 123,
    someFunction: function() {
        alert('hello!');
    }
};

What languages provide the use of object literals? (Or in what languages could you easily emulate them?) Can you give a code example?

Starting with the obvious javascript snippet:

var someObj = {
    someProperty: 123,
    someFunction: function() {
        alert('hello!');
    }
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青瓷清茶倾城歌 2024-10-17 00:40:56

查看 C# 匿名类型

var Customer = new
{
    Company = "AgileApps",
    Website = "http://www.agileapps.co.uk",
    Name = "Big Al",
    Entered = DateTime.Now
};

Checkout C# anonymous types

var Customer = new
{
    Company = "AgileApps",
    Website = "http://www.agileapps.co.uk",
    Name = "Big Al",
    Entered = DateTime.Now
};
雅心素梦 2024-10-17 00:40:56

如果用“term”替换 object,那么 Prolog 会自然地执行此操作(事实上,没有其他方法来构造对象)。这是一个以二叉树为特色的示例:

% find a node in List with a nil left child and call its rightmost grandchild X
member(node(nil,node(_,X)), List).

Lisp 和Scheme 在该领域也有一些相当先进的功能,特别是引用和半引用:

;; construct right-leaning binary tree with x as the rightmost grandchild
`(nil . (nil . ,x))

实际上所有函数式编程语言都以某种形式复制了这一点。

If you replace object by "term," then Prolog does this naturally (in fact, there's no other way to construct an object). Here's an example featuring binary trees:

% find a node in List with a nil left child and call its rightmost grandchild X
member(node(nil,node(_,X)), List).

Lisp and Scheme also have some pretty advances features in this area, particularly quoting and semiquoting:

;; construct right-leaning binary tree with x as the rightmost grandchild
`(nil . (nil . ,x))

Practically all functional programming languages have copied this in some form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文