undefined being treated as a missing optional argument

Russell Leggett russell.leggett at gmail.com
Fri Apr 13 09:38:52 PDT 2012


On Fri, Apr 13, 2012 at 12:26 PM, Allen Wirfs-Brock
<allen at wirfs-brock.com>wrote:

>
> On Apr 12, 2012, at 7:31 PM, Luke Hoban wrote:
>
> ...
>
>
> This is a good way of explaining the proposed semantics, but...
>
> But I see why somebody calling a function defined as function(a={ }){...}
> explicitly as f(undefined) would expect to trigger the default  value
> initializer.
>
>
> Right.  This is exactly the sort of thing I'm worried about, and seems
> like the practical common case for default values.
>
>
> Oops, I meant "I don't see why...".  Some of my negations don't seem to be
> getting from my head to my finger as I type...
>
> Restating, when I type f(undefined)  I'm thinking something quite
> different from f()
>

Yes, but as I said, and Erik pointed out is in the wiki, it is a lot more
likely that someone would pass f(foo) or f(obj.foo) where foo might be
undefined. Expecting undefined as a possible valid argument (as opposed to
a missing argument) seems like a very rare case, and probably a code smell.
I think it would be very unintuitive to the majority of JavaScript
developers, and greatly undermines the usefulness of default parameters for
the sake of a minority use case. In those cases where undefined is an
acceptable parameter, just don't use default parameters.

- Russ


>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120413/abfee341/attachment.html>


More information about the es-discuss mailing list