Oliver Hunt wrote:
On Oct 10, 2012, at 9:12 AM, Allen Wirfs-Brock <[email protected] <mailto:[email protected]>> wrote:
On Oct 10, 2012, at 6:39 AM, David Bruant wrote:

2012/10/10 Keith Cirkel <[email protected] <mailto:[email protected]>>

    You /are/ actually passing in a second argument though, your
    second argument is `undefined`. Default arguments aren't meant
    to replace `undefined` values, they're meant to
    be permissible for omission.


No, that isn't what the draft specification now says. It was originally that way, but TC39 based upon discussions here, decided that an explicit undefined argument value triggers default value initialization.

I still disagree with this decision, but from an implementation standpoint the cost difference is fairly minimal (there is of course an additional runtime performance cost, but i suspect it would be negligible).

The reason for treating undefined (and only undefined) as the sentinel value that triggers defaulting may not be clear to everyone. It is so that delegation layers do not have reproduce all the defaulting logic just to call the target function with the right number of parameters:

  function foo(a, b, c) {
    log(stuff, a, b, c);
    return bar(a, b, c);
  }
  function bar(a = da, b = db, c = dc) {
    ...
  }

Without this, foo(1) and foo(2,3) calls would need to be special-cased in foo's body to call bar with only 1 or 2 arguments.

I guess it depends on whether the committee feels that we should be encouraging the use of null over undefined in new syntactic constructs.

What has null to do with your disagreement with there being a default sentinel? Or did you mean that you disagreed with only undefined being that sentinel?

/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to