Skip to content

Instantly share code, notes, and snippets.

@Sjeiti
Created September 3, 2013 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sjeiti/6422815 to your computer and use it in GitHub Desktop.
Save Sjeiti/6422815 to your computer and use it in GitHub Desktop.
Simple object pool
if (!window.myObj) {
myObj = (function(){
var aPool = [];
function obj(x,y) {
var fX,fY
,oObj = {
set:set
,drop:drop
}
;
set(x,y);
function set(x,y) {
fX = x===undefined?1:x;
fY = y===undefined?0:y;
return oObj;
}
function drop() {
aPool.push(oObj);
}
return oObj;
}
return function(x,y) {
return aPool.length?aPool.pop().set(x,y):obj(x,y);
};
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment