Skip to content

Instantly share code, notes, and snippets.

@kotaroito
Last active August 29, 2015 14:05
Show Gist options
  • Save kotaroito/dc56cf5b5dfe0da2fc72 to your computer and use it in GitHub Desktop.
Save kotaroito/dc56cf5b5dfe0da2fc72 to your computer and use it in GitHub Desktop.
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