Skip to content

Instantly share code, notes, and snippets.

@nazt
Created June 27, 2011 07:52
Show Gist options
  • Select an option

  • Save nazt/1048462 to your computer and use it in GitHub Desktop.

Select an option

Save nazt/1048462 to your computer and use it in GitHub Desktop.
Array.prototype.push
// Appends the arguments to the end of the array and returns the new
// length of the array. See ECMA-262, section 15.4.4.7.
function ArrayPush() {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
throw MakeTypeError("called_on_null_or_undefined",
["Array.prototype.push"]);
}
var n = TO_UINT32(this.length);
var m = %_ArgumentsLength();
for (var i = 0; i < m; i++) {
this[i+n] = %_Arguments(i);
}
this.length = n + m;
return this.length;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment