Skip to content

Instantly share code, notes, and snippets.

@joncasey
Created July 15, 2017 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joncasey/2ca9e309487d978de7e1cf5ab050cde3 to your computer and use it in GitHub Desktop.
Save joncasey/2ca9e309487d978de7e1cf5ab050cde3 to your computer and use it in GitHub Desktop.
Polyfill with a Promise
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