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
1 Answer
Reset to default 7It'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.