Skip to content

Instantly share code, notes, and snippets.

@AdamMadrzejewski
Created August 13, 2015 13:44
Show Gist options
  • Save AdamMadrzejewski/54a5ce14bbc37104ec09 to your computer and use it in GitHub Desktop.
Save AdamMadrzejewski/54a5ce14bbc37104ec09 to your computer and use it in GitHub Desktop.
Promise - document ready
HTMLDocument.prototype.ready = function () {
return new Promise(function(resolve, reject) {
if (document.readyState === 'complete') {
resolve(document);
} else {
document.addEventListener('DOMContentLoaded', function() {
resolve(document);
});
}
});
}
document.ready().then(function () {
console.log('Done! xD');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment