Skip to content

Instantly share code, notes, and snippets.

@okj579
Last active January 11, 2018 16:40
Show Gist options
  • Save okj579/012983dcbbeddc0084b9 to your computer and use it in GitHub Desktop.
Save okj579/012983dcbbeddc0084b9 to your computer and use it in GitHub Desktop.
Queue Proxy
function makeQueueProxy(name){
if (window[name] === undefined) {
var queue = [];
// When function is called, add to queue
function proxy() {
queue.push([this, Array.prototype.slice.apply(arguments)]);
}
window[name] = proxy;
(function check() {
// Check if function has been defined
if (window[name] === proxy) {
// Wait and try again
setTimeout(check, 50);
} else {
// Replay all calls added to the queue
while (queue.length) {
Function.prototype.apply.apply(window[name], queue.shift());
}
}
})();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment