JavaScript 函数参数内的大括号
JavaScript 函数参数周围的大括号有什么作用?
var port = chrome.extension.connect({name: "testing"});
port.postMessage({found: (count != undefined)});
What do the curly braces surrounding JavaScript arguments for functions do?
var port = chrome.extension.connect({name: "testing"});
port.postMessage({found: (count != undefined)});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
自提出此问题以来,出现了第二个可能的答案。 Javascript ES6 引入了解构赋值。
A second possible answer has arisen since this question was asked. Javascript ES6 introduced Destructuring Assignment.
大括号表示对象文字。它是一种发送键/值对数据的方式。
所以这样:
像这样使用来访问数据。
您可以为对象提供多个以逗号分隔的键/值对,只要键是唯一的。
您还可以使用方括号来访问对象的属性。
如果是
“a-key”
,则需要这样做。使用方括号,您可以使用存储在变量中的属性名称来访问值。
The curly braces denote an object literal. It is a way of sending key/value pairs of data.
So this:
Is used like this to access the data.
You can give the object several comma separated key/value pairs, as long as the keys are unique.
You can also use square brackets to access the properties of the object.
This would be required in the case of the
"a-key"
.Using the square brackets, you can access a value using a property name stored in a variable.
JavaScript 中的大括号用作创建对象的简写。例如:
查看 Douglas Crockford 的 JavaScript 调查 了解更多详细信息。
Curly braces in javascript are used as shorthand to create objects. For example:
Check out Douglas Crockford's JavaScript Survey for more detail.
定义一个具有属性的对象文字。你可以这样做
,它将评估为“标题;”
这是将配置传递给方法的常用技术,这就是这里发生的情况。
defines an object literal that has properties on it. you can do
which will evaluate to 'the title;
this is a common technique for passing configurations to methods, which is what is going on here.