Created
October 27, 2010 15:36
-
-
Save cms/649276 to your computer and use it in GitHub Desktop.
Simple `__proto__` based Array sandbox
This file contains 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
var sb = { | |
Array: function() { | |
var result = Array.apply(null, arguments); | |
result.__proto__ = sb.Array.prototype; | |
return result; | |
} | |
}; | |
sb.Array.prototype = []; | |
sb.Array.prototype.last = function () { return this[this.length -1]; }; | |
// Example usage: | |
var a = sb.Array('a','b','c'); | |
a[3] = 'd'; | |
a.length; // 4 | |
a.last(); // "d" | |
var b = sb.Array(10); | |
b.length; // 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment