15.4.4.4 Array.prototype.concat([item1[, item2[, ... ]]])

2010-07-05

array Array.prototype.concat([item1:mixed[, item2:mixed[, ... ]]])

This method joins this array with the elements or arrays supplied as arguments, in order.

The this value is coerced to an object. Returns a new array. Neither the this array nor the method arguments are changed by this operation.

Note that concat only merges ONE level of this array and the arguments. If any array has multiple nested arrays the nested arrays are NOT merged.

Array.prototype.concat.length = 1

Code: (Meta Ecma)
Array.prototype.concat = function(){
var O = ToObject(this);
var A = new Array;
var n = 0;
var items = Array.prototype.slice.call(arguments);
items.unshift(O);
while (items.length) {
var E = items.shift();
if (E.[[Class]] == "Array") {
var k = 0;
var len = E.[[Get]]("length");
while (k < len) {
var P = ToString(k);
var exists = E.[[HasProperty]](P);
if (exists) {
var subElement = E.[[Get]](P);
A.[[DefineOwnProperty]](ToString(n), PD{[[Value]]:subElement, [[Writable]]:true, [[Enumerable]]:true, [[configurable]]:ture}, false);
}
++n;
++k;
}
} else { // E not an array
A.[[DefineOwnProperty]](ToString(n), PD{[[Value]]:E, [[Writable]]:true, [[Enumerable]]:true, [[Configurable]]:true}, false);
++n;
}
}
return A;
}