This proposal has progressed to the Draft ECMAScript 6 Specification, which is available for review here: specification_drafts. Any new issues relating to them should be filed as bugs at http://bugs.ecmascript.org
arguments so we can deprecate, obsolete, and some years hence burn with fire / salt the earth anything to do with arguments, foo.arguments, etc.... as an optional prefix before the last formal parameter in a function declaration... in function foo(...rest) {...} creates a rest parameter, rest, denoting a new Array created when foo is called, whose elements from 0 to foo.length are supplied by the actual arguments passed to foo (if any)function bar(baz, bletch, ...rest) {...}, with elements of rest being supplied by the third through last actual parameters
// Trivial this-free wrapper around Function.prototype.apply:
function simpleApply(func, ...args) {
"use strict";
return func.apply(undefined, args);
}
// Simple printf-style string formatter, write and convert left as exercises:
function printf(format, ...args) {
var n = 0;
var i = 0, j;
while ((j = format.indexOf('%', i)) >= 0) {
if (n >= args.length)
throw "printf: too few args for given format " + format;
write(format.slice(i, j));
// convert takes exactly one format-specifier char, to keep things simple.
write(convert(s[j + 1], args[n++]));
i = j + 2;
}
write(format.slice(i));
}
The FormalParameterList clause needs to be updated as follows:
FormalParameterList :
... Identifier
FormalParameterListNoRest
FormalParameterListNoRest , ... Identifier
FormalParameterListNoRest :
Identifier
FormalParameterListNoRest , Identifier
We let all Function objects have a boolean internal property indicating if it has rest parameters.
| Internal Property | Value Type Domain | Description |
|---|---|---|
| [[HasRestParameter]] | Boolean | Whether the function was declared with a rest parameter. The last parameter in the [[FormalParameters]] List is used for the rest parameter. Of the standard built-in ECMAScript objects, only Function objects implement [[HasRestParameters]]. |
The callers of 13.2 should pass in hasRest which indicates that the function has a rest parameter.
... with no formal parameter identifier after it? Not without types or arity checks.— Brendan Eich 2009/05/04 22:52
The length property of a function should be updated to not include rest parameters.
— Erik Arvidsson 2010/11/05 22:42
The semantics is not yet complete. It needs to get whether FormalParameterList contains rest parameters and forward that to 13.2.
— Erik Arvidsson 2010/11/09 20:47
Functions that define a rest parameter should not also have an arguments object. In other words, using ... in the parameter lists should prevent the creation of the arguments object and the local binding of “arguments”. Should the strict mode restrictions on the use of the identifier “arguments” be relax in that case?
— Allen Wirfs-Brock 2010/11/10 00:17