我在哪里可以获得有关javascript函数的对象参数语法的信息? [英] Where can I get info on the object parameter syntax for javascript functions?
问题描述
如果我想调用这样的函数:
If I want to call a function like this:
moo({ a: 4 });
通常情况下,我必须像这样说出我的函数定义:
Normally i'd have to phrase my function definition like this:
function moo(myArgObj) {
print(myArgObj.a);
}
但这个令人敬畏的语法在spidermonkey中完全有效,用于定义函数:
But this awesome syntax is totally valid in spidermonkey for defining functions:
function moo({ a, b, c }) { // valid syntax!
print(a); // prints 4
}
我能找到相关信息的想法吗?我想看看这个功能有多强大。
Any ideas where I can find info on this? I'd like to see just how powerful this feature is.
我刚才在javascript / ecmascript 5中看过它,但我再也找不到它了。它没有出现在我在youtube上可以找到的任何视频中,并且在标准的PDF本身中没有提到。
I saw it in a javascript/ecmascript 5 talk a while ago, but I can't find it anymore. It doesnt appear in any of the videos I can find on youtube, and it's not mentioned in the standard's PDF itself.
推荐答案
它是称为解构。您可以在 MDN:Destructuring assignment <中找到最多信息/ A>。
It's called destructuring. You might find the most info at MDN: Destructuring assignment.
ECMAScript标准讨论可在他们的wiki页面,也很有趣可能是此博客帖子 at dailyjs。
The ECMAScript standards discussion can be found on their wiki page, also interesting might be this blog post at dailyjs.
这篇关于我在哪里可以获得有关javascript函数的对象参数语法的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!