I’m torn: On one hand, I love the cleverness of it and it is certainly a good solution (and one that doesn’t necessitate introducing new language features).
On the other hand, I’m wondering if it wouldn’t be cleaner to have a per-function flag that tells JavaScript to enforce the specified arity (which can be done quite precisely, thanks to ES6’s advanced parameter handling). One possibility for setting such a flag are Python-style decorators: http://www.python.org/dev/peps/pep-0318/ Axel On Jan 7, 2013, at 20:33 , Brendan Eich <bren...@mozilla.com> wrote: > Jason Orendorff wrote: >> On Sun, Jan 6, 2013 at 6:31 PM, Axel Rauschmayer <a...@rauschma.de >> <mailto:a...@rauschma.de>> wrote: >> >> What is the simplest way of enforcing an arity in ES6? Doesn’t it >> involve arguments? >> >> >> Hmm. Can you do this? >> >> function f(x, y, ...[]) {} > > The question is, with refutable-by-default, does the empty array pattern fail > on any non-empty arraylike match target? If yes, then we need a way to match > prefixes of arraylikes (including empty prefixes!): > > let [] = must_be_empty(); > let [...many] = however_many(); > let [first?, second?] = two(); > > I buy it! > > /be > -- Dr. Axel Rauschmayer a...@rauschma.de home: rauschma.de twitter: twitter.com/rauschma blog: 2ality.com
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss