Re: an idea for replacing arguments.length

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.

Received on Monday, 11 November 2013 19:38:08 UTC