Enforcing arity

Axel Rauschmayer axel at rauschma.de
Sat Mar 16 17:24:40 PDT 2013


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130317/d0206496/attachment.html>


More information about the es-discuss mailing list