Using destructuring for function arguments

Kevin Smith zenparsing at gmail.com
Sat May 31 13:58:31 PDT 2014


In addition to what Allen said, you could also do something like this:

    function setCookie(name, value, { secure, path, domain, expires } =
cookieDefaults) { }

where `cookieDefaults` is defined elsewhere.

Or you could do something like:

    function setCookie(name, value, { secure = false, path = ".", domain =
"", expires = now() } = {}) { }

where you are specifying default initializers within the destructuring
pattern.

​Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140531/fe597ee2/attachment.html>


More information about the es-discuss mailing list