1) "#" is one of the few ascii characters we haven't used up yet. Let's not use it up on a minor convenience.
2) Introducing new syntax for use cases that are expected to be frequent, e.g., classes, often pays for its weight. The frequency makes it likely that readers will understand what it is the vast majority of times they encounter it. New syntax that gets used once in a blue moon can only be justified if the pain of doing without in those blue-moon cases is huge. In this case, it isn't. For those rare occasions when they see it, readers are much more likely to guess what "arguments.length" mean that this funny newfangled "#" thing. Code is read much more often than it is written -- at least code that matters. Brevity is useful as a metric only to the degree that it serves as a proxy for cognitive load on the reader. On Sun, Nov 10, 2013 at 10:12 AM, Allen Wirfs-Brock <[email protected]>wrote: > One of the the few remaining uses of a function's 'arguments' binding is > to determine the actual number of passed arguments. This is necessary in > some overloading scenarios where a function has different behavior when an > argument is completely absent then it has when undefined (or any other > default value) is explicitly passed in that parameter position. That > situation occurs in a number of DOM APIs and even a few ES library > functions. > > For example(see https://bugs.ecmascript.org/show_bug.cgi?id=1877 ), > Array.prototype.splice returns different results for: > [1,2,3].splice() > and > [1,2,3].splice(undefined) > > The natural ES6 declaration for a splice function is: > > function splice(start, deleteCount, ...items) {... > > but if you write it this way then within the body you have to have a test > like: > > if (arguments.length == 0) {... > > to implement the correct web-compatable behavior. > > Or, alternatively you could declare the functions as: > > function splice(...actualArgs) { > let [start, stop, ...item] = actualArgs; > ... > if (actualArgs.length == 0) {... > > So, to implement a Web-compaable version of splice you either have to use > 'arguments' to determine the actual number of passed objects or you need to > declare it with a bogus parameter pattern and use explicit or implicit > destructuring to parse out the positional parameters. > > One way around this dilemma would be to provide a syntactic affordance for > determing the actual argument count. For example, one possibility would be > to allow the last item of any formal parameter list to be an item of the > syntactic form: > > ActualArgumentCount : '#' BindingIdentifier > > So, the declaration for splice could then be: > > function splice(start, deleteCount, ...items, #argCount) { > ... > if (argCount == 0) {... > > Thoughts? > > Allen > > > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > > -- Cheers, --MarkM
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

