Skip to content

Commit

Permalink
Detect global in strict mode and WebWorkers; fixes jashkenas#2152
Browse files Browse the repository at this point in the history
  • Loading branch information
megawac committed May 14, 2015
1 parent 4f2474c commit 68bb747
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
// Baseline setup
// --------------

// Establish the root object, `window` in the browser, or `exports` on the server.
var root = this;
// Establish the root object, `window` (`self`) in the browser, or `global` on the server.
// We use `self` instead of `window` for `WebWorker` support.
var root = (typeof self == 'object' && self.self == self && self) ||
(typeof global == 'object' && global.global == global && global);

// Save the previous value of the `_` variable.
var previousUnderscore = root._;
Expand Down Expand Up @@ -1562,4 +1564,4 @@
return _;
});
}
}.call(this));
}());

0 comments on commit 68bb747

Please sign in to comment.