-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Simplify reference to the global object #292
Conversation
See also: #112 It's good that this doesn't use |
What about this? (function(){return this}()) || Function("return this")() This avoids using the |
typeof global === "object" ? global : | ||
typeof window === "object" ? window : | ||
typeof self === "object" ? self : this; | ||
var g = (function { return this })(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An anonymous and parameter-less function?? Think you need a ()
, as the tests will surely tell you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, I guess none of the tests use runtime-module.js
, huh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Darn it, knew I forgot something. I'll fix it right away.
Yeah, the strict code thing is real. But it should be safe as long as you don't blindly concatenate all your JS together with the I think most, if not all, users of this library uses a bundler, which I hope uses a function closure to keep things separate. Then it's fine if something else is using top level strict mode.
(function(){return this}()) || Function("return this")() That looks like the ticket. I'll get it in, and fix the other thing you pointed out. |
Take advantage of sloppy mode, aka non-strict mode, where unbound functions are called with the global object as `this`. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#Securing_JavaScript
I'm implemented that fix, and squashed the commits while I was at it. |
Thanks for working on this, and sorry it sat unmerged for so long! |
No worries, life happens. |
Take advantage of sloppy mode, aka non-strict mode, where unbound functions are called with the global object as
this
.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#Securing_JavaScript