Anonymous user
Named parameters: Difference between revisions
→ECMAScript 2015 (ES6) variants
(→ECMAScript 2015 (ES6) variants: Marked incorrect.) |
|||
Line 597:
// => "foo is 0, bar is 3.14, and grill is lamb kebab"</lang>
===ECMAScript 2015 (ES6) variants===
With this version, ECMAScript adds destrucuring assignments and destructuring in function parameters. Thus you could do something like this (this works in ES6 Fiddle, but is syntax error in Mozilla SpiderMonkey JS Shell, so uses console.log instead of print):<lang javascript>let
example = // The member name in the object can either be the same as the parameter (as in bar, grill),
// or a different parameter name as in the case of member foo being assigned to parameter a here.
console.log('foo is ',a,', bar is ',bar,', and grill is '+grill));
example();
|