Continuing woes in reading the ES6 spec language
Tab Atkins Jr.
jackalmage at gmail.com
Fri Sep 13 15:07:55 PDT 2013
On Fri, Sep 13, 2013 at 2:52 PM, Sebastian Zartner
<sebastianzartner at gmail.com> wrote:
>>> * You can pass undefined to trigger defaulting -- this is important for
>>> composition / delegation.
>> No, it's a terrible feature :D i'm unaware of any language that supports
>> arbitrary ordering of arguments.
> FWIW, ColdFusion allows to call functions with named parameters in an
> arbitrary order. This has one benefit: You can simply skip arguments in
> the middle instead of having to provide a default value for them the call.
A likely-more-familiar example is Python, which is the same - you can
provide any argument by name, in any order. Actually, any language I
can think of that lets you pass arguments by name allows this, so I've
no idea what Oliver is going on about. (As Brendan has said, JS won't
grow named arguments a la Python, but its equivalent functionality -
using an options object + destructuring - also allows passing the
arguments in arbitrary order.)
Furthermore, as Brendan pointed out, this statement has nothing to do
with named arguments, it's about argument defaulting. When creating
"wrapper" functions, if the wrapped function has default values for
some arguments, you need a succinct way to say "I don't actually want
to pass this argument, even though I'm giving you a value - just use
the default value instead".
If you don't have this, you end up having to create a combinatorial
explosion of call paths for the wrapped function, one for each
possible set of defaulted arguments. I know how frustrating this is
first-hand, because Common Lisp has several functions that act
differently based on whether an argument is passed or not, and
wrapping them is extremely clumsy and frustrating.
To get around it, JS has defined that passing undefined triggers
defaulting behavior, identical to if you didn't pass any value at all.
This lets the wrapper not provide any defaults at all, and just do a
pass-through of its arguments - if the caller didn't pass a given
argument, the wrapper will get "undefined" in that arg, and pass it on
to the wrapped function, which will then do its proper defaulting
More information about the es-discuss