Re: Using destructuring for function arguments

2014-06-03 Thread Nicholas C. Zakas
On 5/31/2014 1:54 PM, Allen Wirfs-Brock wrote: What happens here is that none of `secure`, `path`, `domain`, `expires` are defined. I can use `typeof` on them to protect against this, but then I end up with some lousy looking code: not really, the thrown exception while processing the

Re: Using destructuring for function arguments

2014-06-01 Thread Brendan Eich
Dmitry Soshnikov wrote: On Sat, May 31, 2014 at 1:41 PM, Brendan Eich bren...@mozilla.org mailto:bren...@mozilla.org wrote: Matthew Robb wrote: Seems like any identifiers in the arguments should always be defined in scope before ever considering what they will be

Using destructuring for function arguments

2014-05-31 Thread Nicholas C. Zakas
I've been playing around with using destructuring as function arguments and have come across some odd behaviors that I'm not sure are intentional (or perhaps, not to spec). For context, consider the following function: ``` function setCookie(name, value, { secure, path, domain, expires

Re: Using destructuring for function arguments

2014-05-31 Thread Matthew Robb
Seems like any identifiers in the arguments should always be defined in scope before ever considering what they will be assigned. On May 31, 2014 11:59 AM, Nicholas C. Zakas standa...@nczconsulting.com wrote: I've been playing around with using destructuring as function arguments and have come

Re: Using destructuring for function arguments

2014-05-31 Thread Dmitry Soshnikov
On Sat, May 31, 2014 at 11:59 AM, Nicholas C. Zakas standa...@nczconsulting.com wrote: I've been playing around with using destructuring as function arguments and have come across some odd behaviors that I'm not sure are intentional (or perhaps, not to spec). For context, consider

Re: Using destructuring for function arguments

2014-05-31 Thread Brendan Eich
Nicholas C. Zakas wrote: ``` function setCookie(name, value, { secure, path, domain, expires } = {}) { console.log(secure); // ... } ``` Unfortunately, that resulted in a syntax error in Firefox. Could you please file a bug against SpiderMonkey? Thanks, /be

Re: Using destructuring for function arguments

2014-05-31 Thread Brendan Eich
Matthew Robb wrote: Seems like any identifiers in the arguments should always be defined in scope before ever considering what they will be assigned. Right, and they are in scope no matter what. Seems to me that an implementation bug (can't have parameter default value for destructuring

Re: Using destructuring for function arguments

2014-05-31 Thread Allen Wirfs-Brock
On May 31, 2014, at 8:59 PM, Nicholas C. Zakas standa...@nczconsulting.com wrote: I've been playing around with using destructuring as function arguments and have come across some odd behaviors that I'm not sure are intentional (or perhaps, not to spec). Argument binding initialization

Re: Using destructuring for function arguments

2014-05-31 Thread Jason Orendorff
On Sat, May 31, 2014 at 1:59 PM, Nicholas C. Zakas standa...@nczconsulting.com wrote: 1. Who is right about assigning a default value to a destructured parameter, Firefox or Traceur? Traceur is right. 2. Is the behavior of not having any bindings for destructured parameter properties

Re: Using destructuring for function arguments

2014-05-31 Thread Kevin Smith
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,

Re: Using destructuring for function arguments

2014-05-31 Thread Kevin Smith
Or, for more readable code: function setCookie(name, value, options = {}) { let { secure = false, path = , domain = , expires = whenever() } = options; // Do stuff } Kevin ​

Re: Using destructuring for function arguments

2014-05-31 Thread Dmitry Soshnikov
On Sat, May 31, 2014 at 1:41 PM, Brendan Eich bren...@mozilla.org wrote: Matthew Robb wrote: Seems like any identifiers in the arguments should always be defined in scope before ever considering what they will be assigned. Right, and they are in scope no matter what. Seems to me that an