Created
July 15, 2017 00:20
-
-
Save joncasey/2ca9e309487d978de7e1cf5ab050cde3 to your computer and use it in GitHub Desktop.
Polyfill with a Promise
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 polyfill (feature, url) { | |
return new Promise(function (resolve, reject) { | |
if (!!feature) return resolve(feature) | |
var el = document.createElement('script') | |
el.async = el.defer = true | |
el.src = url | |
el.onload = function () { resolve(url) } | |
el.onerror = function (e) { reject(e) } | |
document.head.appendChild(el) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment