W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2013

Re: an idea for replacing arguments.length

From: Brandon Benvie <bbenvie@mozilla.com>
Date: Mon, 11 Nov 2013 11:37:44 -0800
Message-ID: <52813208.7050103@mozilla.com>
To: Corey Frang <gnarf37@gmail.com>, "Tab Atkins Jr." <jackalmage@gmail.com>
CC: "Mark S. Miller" <erights@google.com>, "public-script-coord@w3.org" <public-script-coord@w3.org>, "es-discuss@mozilla.org list" <es-discuss@mozilla.org>
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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:19 UTC