14 Sep 2015, 00:00

Default function options stash with ES6 destructuring assignment.

Share

ES6 opens up a clean approach to define function options stash thanks to the destructuring assignment syntax,

Assuming we want options but let the user overrides it, we can declare our function that way:

function hello(param1, {debug = true, whatever = false} = {}) { }

The advantages are, clearly there is no code in the body function to achieve default options & user overrides.

comments powered by Disqus