What is the simplest way of enforcing an arity in ES6? Doesn’t it involve 
arguments?

function add(x, y) {
    if (arguments.length !== 2) throw ...
}

To avoid `argument`, one could:
- ensure a maximum arity by adding a ...rest parameter and checking that its 
length is 0.
- ensure a minimum arity, by giving y a default value and checking for it.

Would fail-fast destructuring work?

function add(...args) {
    let [x,y] = args;
}

-- 
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

Reply via email to