Last active
December 26, 2015 19:39
-
-
Save jtenner/7202463 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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