global is undefined in a strict environment
See original GitHub issueThe following code will be generated when using the es6-set polyfill in a Rollup IIFE build:
(function() {
"use strict";
var isImplemented = function() {
// ...
};
/* eslint strict: "off" */
var global = (function() {
return this;
})();
if (!isImplemented()) {
Object.defineProperty(global, "Set", {
value: polyfill$1,
configurable: true,
enumerable: false,
writable: true
});
}
})();
global will be undefined because of the "use strict";, and the error Object.defineProperty: argument is not an Object will be thrown.
Is the recommended solution to remove the "use strict";, or could perhaps the global implementation be changed to something along the lines of the implementation in core-js?
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
var global =
typeof window == "object" && window && window.Math == Math
? window
: typeof self == "object" && self && self.Math == Math
? self
: Function("return this")();
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Getting a reference to the global object in an unknown ...
This technique will work for any host environment, but not in strict mode, because an undefined this does not reference the global object...
Read more >Global app variables under "use strict" · Issue #1380 - GitHub
It seems it is impossible to define global app variables when running code under "use strict". In documentation it is written:.
Read more >Detecting Undefined Variables - lua-users wiki
The reason is that if a variable is not recognized by Lua as a local variable (e.g. by static declaration of the variable...
Read more >globalThis - JavaScript - MDN Web Docs
The this keyword could be used inside functions running in non–strict mode, but this will be undefined in modules and inside functions running ......
Read more >What is globalThis, and why should you start using it?
The globalThis proposal, now in stage 4, aims to consolidate the increasingly fragmented ways of accessing the global object in JavaScript.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@medikoo CSP is not an issue since in engines where it’s possible we check
windowandselfbefore usage ofFunctionconstructor.I’ll just leave this here: https://mathiasbynens.be/notes/globalthis