Enforcing arity

Kevin Gadd kevin.gadd at gmail.com
Sat Mar 16 17:27:42 PDT 2013


Would using (...args) incur a performance penalty and impair
optimization since the argument list has to be an array now? Or is
that still better than using 'arguments.length'? Enforcing arity is a
common enough (and important, IMO) pattern that I'd be wary of doing
it using a pattern that is going to slow everything down. Something
that makes every call create garbage seems like a likely candidate to
do that.

-kg

On Sat, Mar 16, 2013 at 5:24 PM, Axel Rauschmayer <axel at rauschma.de> wrote:
> On Mar 17, 2013, at 1:17 , Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>
> If you need to do arity analysis of parameter but also what to apply default
> values, destructuring, etc I would do the following:
>
> Instead of
>    function ([a,b], c,d=5, ...rest) {...}
> do
>    function (...args) {
>        if (args.length <3) throw Error("too few arguments");  // (*)
>        let [[a,b], c,d=5, ...rest] = args;  //probably need some ?'s in
> there, but I haven't internalized the details of the new pattern matching
> yet.
>    }
>
>
> Nice, I forgot about rest parameters. You’d still get an exception from
> matching if you omitted line (*), right?
> Shame that we can’t have the destructuring semantics for parameters.
>
> --
> Dr. Axel Rauschmayer
> axel at rauschma.de
>
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list