Created
March 5, 2015 17:57
-
-
Save SparK-Cruz/ee3807d81fca6668a9d9 to your computer and use it in GitHub Desktop.
Function deferring for javascript
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
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