Function length

Erik Arvidsson erik.arvidsson at gmail.com
Sat Jun 9 23:39:44 PDT 2012


On Sat, Jun 9, 2012 at 9:08 PM, Rick Waldron <waldron.rick at gmail.com> wrote:
> I just noticed strange behavior in spider monkey implementation of rest
> arguments:
>
> (function(a, b, ...rest) {}).length // => 2
>
> I agree that this is strange, I would expect 3, as there are three formally
> named parameters.

The length in ES5 is not very consistent.

For ES6 we decide that we wanted the function length to be used to
tell how many required parameters a function has.

Today rest params are done using arguments:

(function(a, b) {
  var rest = Array.prototype.slice.call(arguments, 2);
}).length  // => 2

The rule is that optional and rest parameters are not included in the
length of the function.

-- 
erik


More information about the es-discuss mailing list