destructuring in formal parameters?

Peter Michaux petermichaux at gmail.com
Thu Nov 13 14:57:14 PST 2008


I've passed a single object to a function in order to simulate named
parameters. This requires some destructuring at the top of the called
function.

function f(params) {
  var foo = params.foo;
  var bar = params.bar;
  //...
}
f({foo:1, bar:2});

With destructuring this could be reduced to

function f(params) {
  var {foo, bar} = params;
  //...
}

f({foo:1, bar:2});

Could it be reduced even further to the following syntax?

function f({foo, bar}) {
  //...
}

f({foo:1, bar:2});

Peter


More information about the Es-discuss mailing list