最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ecmascript 6 - Where can I get info on the object parameter syntax for JavaScript functions? - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Jul 23, 2019 at 12:44 Kyll 7,1538 gold badges44 silver badges64 bronze badges asked May 29, 2012 at 18:54 VerdagonVerdagon 2,6304 gold badges24 silver badges43 bronze badges 1
  • Didn't you miss the property names in that arguments "object declaration"? – Bergi Commented May 29, 2012 at 19:27
Add a ment  | 

1 Answer 1

Reset to default 7

It's called destructuring. You might find the most info at MDN: Destructuring assignment (especially see Unpacking fields from objects passed as function parameter).


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

发布评论

评论列表(0)

  1. 暂无评论