Last active
January 11, 2018 16:40
-
-
Save okj579/012983dcbbeddc0084b9 to your computer and use it in GitHub Desktop.
Queue Proxy
This file contains 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 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