diff --git a/.jshintrc b/.jshintrc index 7427dce48..c66d74c88 100644 --- a/.jshintrc +++ b/.jshintrc @@ -20,6 +20,7 @@ "browser": true, "node": true, "globals": { + "self": true, "define": true } } diff --git a/lib/async.js b/lib/async.js index 59ff57b97..41d33cb4a 100644 --- a/lib/async.js +++ b/lib/async.js @@ -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;