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.
}
Allen
On Mar 16, 2013, at 5:02 PM, Axel Rauschmayer wrote:
> What is the recommended way of enforcing arity under ECMAScript 6 (while
> avoiding arguments.length)?
>
> Two ideas:
>
> 1. Parameter default value is a function call that throws an exception. Not
> sure if that works.
> function foo(required = throwAnException(), optional) { ... }
>
> 2. Introduce a postfix `!` matching operator, the inverse of postfix `?`:
> function foo(required!, optional) { ... }
>
> --
> Dr. Axel Rauschmayer
> [email protected]
>
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss