Skip to content

Instantly share code, notes, and snippets.

@SparK-Cruz
Created March 5, 2015 17:57
Show Gist options
  • Save SparK-Cruz/ee3807d81fca6668a9d9 to your computer and use it in GitHub Desktop.
Save SparK-Cruz/ee3807d81fca6668a9d9 to your computer and use it in GitHub Desktop.
Function deferring for javascript
Function.prototype.defer = function(thisObj, parameters){
if (typeof parameters == "undefined")
parameters = [];
if (typeof window.deferredActionsList === "undefined")
window.deferredActionsList = [];
if (typeof window.__deferredActionsRunner === "undefined")
window.__deferredActionsRunner = setTimeout(function(){
for(var key in window.deferredActionsList){
obj = window.deferredActionsList[key]
obj.action.apply(obj.thisObj, obj.parameters);
}
}, 0);
window.deferredActionsList.unshift({action: this, thisObj: thisObj, parameters: parameters});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment