Re: Destructuring and default parameters in functions
Good to see that the expected functionality is also how it is intended to function. Hopefully the bug Brandon referred to will be fixed soon, so it can be tested in a browser. By using default params and destructuring a neat module loading syntax can be defined (as opposed to the import syntax of ES6 or the array in AMD): https://gist.github.com/mariusGundersen/5884450 Marius Gundersen On Thu, Jun 27, 2013 at 8:27 PM, Brandon Benvie bben...@mozilla.com wrote: On 6/27/2013 3:19 AM, Marius Gundersen wrote: Or maybe it just isn't implemented in Firefox? This is correct. https://bugzilla.mozilla.org/**show_bug.cgi?id=884372https://bugzilla.mozilla.org/show_bug.cgi?id=884372 __**_ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/**listinfo/es-discusshttps://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Destructuring and default parameters in functions
I'm testing some code in the latest version of Firefox, and it seems I'm not able to define default values to function arguments which are destructured. For example: function test([a, b] = [1, 2]){ return a+b; } test([3, 4])//expect 7 test([3])//expect NaN test()//expect 3 //Exception: missing ) after formal parameters (line 1) I haven't found this defined in the current grammar, but would be useful for something I'm currently working on. Or maybe it just isn't implemented in Firefox? Marius Gundersen ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Destructuring and default parameters in functions
That should work and it works both in Traceur and Continuum. On Thu, Jun 27, 2013 at 6:19 AM, Marius Gundersen gunder...@gmail.com wrote: I'm testing some code in the latest version of Firefox, and it seems I'm not able to define default values to function arguments which are destructured. For example: function test([a, b] = [1, 2]){ return a+b; } test([3, 4])//expect 7 test([3])//expect NaN test()//expect 3 //Exception: missing ) after formal parameters (line 1) I haven't found this defined in the current grammar, but would be useful for something I'm currently working on. Or maybe it just isn't implemented in Firefox? Marius Gundersen ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss -- erik ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Destructuring and default parameters in functions
On Jun 27, 2013, at 3:19 AM, Marius Gundersen wrote: I'm testing some code in the latest version of Firefox, and it seems I'm not able to define default values to function arguments which are destructured. For example: function test([a, b] = [1, 2]){ return a+b; } test([3, 4])//expect 7 test([3])//expect NaN test()//expect 3 //Exception: missing ) after formal parameters (line 1) I haven't found this defined in the current grammar, see http://people.mozilla.org/~jorendorff/es6-draft.html#sec-13 FormalParameter : BindingElement http://people.mozilla.org/~jorendorff/es6-draft.html#sec-12.2.4 BindingElement : BindingPattern Initialiseropt BindingPattern : ArrayBindingPattern but would be useful for something I'm currently working on. Or maybe it just isn't implemented in Firefox? Marius Gundersen ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Destructuring and default parameters in functions
On 6/27/2013 3:19 AM, Marius Gundersen wrote: Or maybe it just isn't implemented in Firefox? This is correct. https://bugzilla.mozilla.org/show_bug.cgi?id=884372 ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss