-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect global in strict mode and WebWorkers #2153
Conversation
It bothers me that the only detection we do now is via de facto self-references on the global object. I wish there was a more reliable way to do this, though at the same time I don't want it to be possible to get a reference to the global object in strict mode. |
// Establish the root object, `window` in the browser, or `exports` on the server. | ||
var root = this; | ||
// Establish the root object, `window` in the browser, or `global` on the server. | ||
var root = typeof self == 'object' && self.Object == Object && self; |
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.
self.Object == Object
would be better as self.self === self
.
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.
Good call
I'm not entirely sure how to test, but what are |
Yeah |
@megawac no, I believe |
👍. We should also apply this to Backbone. |
I've just fixed this in Backbone like so (a little looser): jashkenas/backbone@5a6ffcb Any objections? |
It probably won't hurt much in Backbone, but avoiding
|
Merging in light of jashkenas/backbone#3602. |
Detect global in strict mode and WebWorkers
@jashkenas may justify a patch release On Thu, May 14, 2015 at 12:02 PM, Justin Ridgewell <notifications@github.com
|
I would like to point out that if you use a build tool like browserify, a reference to (function (global){
/** your original module **/
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) I'm only pointing this out for the benefit of those that use browserify and wonder why underscore gets that wrapper. I'm not suggesting to build underscore with browserify, and I'm not suggesting this is a bad change. |
This fix was merged with master in May, 2015. Almost 2 years later, can we release a patch? |
I second the request from @dcocchia ? can you distribute the fix as a new release, please? |
fixes #2152