Skip to content

Instantly share code, notes, and snippets.

@jasonhofer
Last active March 11, 2023 16:27
Show Gist options
  • Save jasonhofer/dd63635c16a4060abad3 to your computer and use it in GitHub Desktop.
Save jasonhofer/dd63635c16a4060abad3 to your computer and use it in GitHub Desktop.
const init = new function () {
let funcs = [],
booted = 0,
doc = document,
ready = fn => {
'loading' === doc.readyState ?
doc.addEventListener('DOMContentLoaded', fn) :
fn();
};
this.push = fn => {
booted ? ready(fn) : funcs.push(fn);
};
this.boot = () => {
if (!booted) {
booted = 1;
funcs.forEach(fn => ready(fn));
}
};
};
/* minified */
const init=new function(f=[],b=0,d=document,r=c=>"loading"===d.readyState?d.addEventListener("DOMContentLoaded",c):c()){this.push=c=>{b?r(c):f.push(c)};this.boot=_=>{if(!b){b=1;f.forEach(c=>r(c))}}};
/* jQuery version */
const init=new function(f=[],b=0){this.push=c=>{b?$(c):f.push(c)};this.boot=_=>{if(!b){b=1;f.forEach(c=>$(c))}}};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment