Where can I get info on the object parameter syntax for JavaScript functions?

我的未来我决定 提交于 2019-12-16 20:03:11

问题


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
}

What is this feature?


回答1:


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.



来源:https://stackoverflow.com/questions/10804982/where-can-i-get-info-on-the-object-parameter-syntax-for-javascript-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!