Enforcing arity

Axel Rauschmayer axel at rauschma.de
Sat Mar 16 17:02:47 PDT 2013


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
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/4d175861/attachment.html>


More information about the es-discuss mailing list