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);
}

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.

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.


It's called destructuring. You might find the most info at MDN: Destructuring assignment.


The ECMAScript standards discussion can be found on their wiki page, also interesting might be this blog post at dailyjs.

链接地址: http://www.djcxy.com/p/52202.html

上一篇: .NET / Mono或Java是更好的交叉选择

下一篇: 我在哪里可以获得有关javascript函数的对象参数语法的信息?