Skip to content

Instantly share code, notes, and snippets.

@jtenner
Last active December 26, 2015 19:39
Show Gist options
  • Save jtenner/7202463 to your computer and use it in GitHub Desktop.
Save jtenner/7202463 to your computer and use it in GitHub Desktop.
function SubArray(length){
Array.call(this); //"Magic"
if(typeof length === "number" && length%1===0&&arguments.length===1){
this.length = length; //Length has to be set manually for some reason.
}
else{
var _len = arguments.length;
this.length = _len;
for(var i = 0; i<_len; i++)
this[i] = arguments[i];
}
}
SubArray.prototype = [];
SubArray.prototype.Length = function(len){
if(typeof len === "number" && len%1===0)
{
this.length = len;
return len;
}
var i = 0, truthy = true;
while(truthy){
truthy = (!!this[i++])||this.length >= i;
}
this.length = i;
return i;
}
var x = new SubArray();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment