Skip to content

Instantly share code, notes, and snippets.

@dcorking
Created August 10, 2021 10:21
Show Gist options
  • Save dcorking/fbd203c6696f9b2502af6bfc0b119116 to your computer and use it in GitHub Desktop.
Save dcorking/fbd203c6696f9b2502af6bfc0b119116 to your computer and use it in GitHub Desktop.
detect global JS feature
// from https://github.com/github/fetch/blob/master/fetch.js
// detecting the existince of fetch() and only patching if it is absent
var global =
(typeof globalThis !== 'undefined' && globalThis) ||
(typeof self !== 'undefined' && self) ||
(typeof global !== 'undefined' && global) ||
{}
export function fetch(input, init) {
return new Promise(function(resolve, reject) {
// ...
}
}
fetch.polyfill = true
if (!global.fetch) {
global.fetch = fetch
global.Headers = Headers
global.Request = Request
global.Response = Response
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment