Last active
August 29, 2015 14:05
-
-
Save kotaroito/dc56cf5b5dfe0da2fc72 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
var MyImmutableArray = (function() { | |
var flyweight = {}; | |
return function(from, to) { | |
var k = from + ':' + to; | |
if (!flyweight[k]) { | |
var array = []; | |
for (var i = from; i <= to; i++) { | |
array.push(i); | |
} | |
flyweight[k] = array; | |
} | |
return flyweight[k]; | |
}; | |
})(); | |
MyImmutableArray.prototype = Array.prototype; | |
console.log(new MyImmutableArray(1, 10000)); | |
console.log(new MyImmutableArray(1, 10000)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment