Skip to content

Instantly share code, notes, and snippets.

@abecoffman
Created April 20, 2011 06:17
Show Gist options
  • Save abecoffman/930483 to your computer and use it in GitHub Desktop.
Save abecoffman/930483 to your computer and use it in GitHub Desktop.
Subclassing arrays in javascript doesn't work as expected
function subArray() {
this.push.apply(this, arguments);
};
subArray.prototype = [];
var sub = new subArray(1,2,3);
alert(sub.length); // 3
sub.push(4);
alert(sub.length); // 4
sub[10] = 10;
alert(sub.length); // 4, should be 11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment