Last active
August 29, 2015 14:02
-
-
Save ninjasort/44f054e61305d1e12d13 to your computer and use it in GitHub Desktop.
Async Function Queueing
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
var _aq = [], | |
funcs = [function () { | |
console.log('Handler 1 executed.'); | |
}, function () { | |
console.log('Handler 2 executed.'); | |
}]; | |
_aq.push(funcs); | |
(function() { | |
var aq = document.createElement('script'); | |
aq.setAttribute('class', 'aq'); | |
aq.async = true; | |
aq.src = 'http://domain.com/async-exec.js'; | |
var s = document.querySelector('.aq')[0]; | |
s.parentNode.insertBefore(gq,s); | |
})(); |
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
'use strict'; | |
(function (handlers, w, d, u) { | |
var i; | |
// executre handlers in queue | |
for(i = 0; i < handlers.length; i++) { | |
h = hanlders[i]; | |
h.apply(w, h.arguments); | |
} | |
})(_aq, window, document, undefined); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment