Skip to content

Commit 8bb6e31

Browse files
fix: prevent hoisting of the undefined global variable in browser.js (#1534)
Because of JS hoisting `var global` to the top of the file, `typeof global` in `getGlobal()` will always be `undefined`. By using a different variable name like `globalObject`, we are able to read the "real" `typeof global` and get access to the global object that way.
1 parent e218f8d commit 8bb6e31

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

browser.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ var getGlobal = function () {
1111
throw new Error('unable to locate global object');
1212
}
1313

14-
var global = getGlobal();
14+
var globalObject = getGlobal();
1515

16-
module.exports = exports = global.fetch;
16+
module.exports = exports = globalObject.fetch;
1717

1818
// Needed for TypeScript and Webpack.
19-
if (global.fetch) {
20-
exports.default = global.fetch.bind(global);
19+
if (globalObject.fetch) {
20+
exports.default = globalObject.fetch.bind(global);
2121
}
2222

23-
exports.Headers = global.Headers;
24-
exports.Request = global.Request;
25-
exports.Response = global.Response;
23+
exports.Headers = globalObject.Headers;
24+
exports.Request = globalObject.Request;
25+
exports.Response = globalObject.Response;

0 commit comments

Comments
 (0)