Sure, it makes some sense when you see it like that :) I retract my "this doesn't make sense"
I guess we are stuck with (...args) On Mon, Nov 11, 2013 at 2:37 PM, Brandon Benvie <[email protected]> wrote: > On 11/11/2013 11:31 AM, Corey Frang wrote: > > I hate to bring this up, as I'm sure I've missed a bunch of the arguments > that define WHY, but if this is the case, it seems unintuitive to me that > passing undefined still results in a default param being set. > > > function test(a = 1) { console.log(a); } > > test(); // gets 1 - yay > test(undefined); // gets 1 - boo! Expect: undefined > > (sorry tab, forgot to reply all on the first reply :( ) > > > The reason for this is so that you can do: > > ```js > function foo(bar) { > return delegatedFoo("foo", bar); > } > > function delegatedFoo(foo, bar = "bar") { > return foo + bar; > } > > foo(); // "foobar" and not "fooundefined" > ``` > > This kind of argument-passing delegation is a very common in JS. >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

