Skip to content

Commit

Permalink
Improve the detection of global/root object
Browse files Browse the repository at this point in the history
  • Loading branch information
megawac committed Jun 24, 2015
1 parent 4722bb5 commit d2dd36b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"browser": true,
"node": true,
"globals": {
"self": true,
"define": true
}
}
19 changes: 8 additions & 11 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@
function noop() {}

// global on the server, window in the browser
var root, previous_async;

if (typeof window == 'object' && this === window) {
root = window;
}
else if (typeof global == 'object' && this === global) {
root = global;
}
else {
root = this;
}
var previous_async;

// Establish the root object, `window` (`self`) in the browser, `global`
// on the server, or `this` in some virtual machines. 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 ||
this;

if (root != null) {
previous_async = root.async;
Expand Down

0 comments on commit d2dd36b

Please sign in to comment.