15.4.2.1 new Array([item0[, item1[, ...]]])

2010-07-04

array new Array([item0:mixed[, item1:mixed[, ...]]])

This description only applies when new Array has been called with zero, two or more arguments. See 15.4.2.2 for the behaviour with one argument.

The new array object gets:
[[Prototype]]: the original Array prototype object (15.4.3.1).
[[Class]]: "Array"
[[Extensible]]: true
length: arguments.length

Code: (Meta Ecma)
function Array(){
if (arguments.length != 1) {
var n = arguments.length;
var a = new Object;
a.[[Prototype]] = Array.prototype;
a.[[Class]] = "Array";
a.[[Extensible]] = true;
a.length = arguments.length;
for (var i=0; i // i'm messing up here, aint i...
a[i ] = PD{[[Value]]:arguments[i ], [[Writable]]:true, [[Enumerable]]:true, [[Configurable]]:true};
}
return a;
}
}

Note that to create a new array, you should use the shorthand notation: []. This notation is slightly faster in most browsers (although minimally so), and doesn't suffer from the side effects the constructor has with a single parameter.