Skip to content

Commit

Permalink
Better support for browsers.
Browse files Browse the repository at this point in the history
In a RequireJS environment `this` doesn't refer to the `window` object, so async doesn't work there.
  • Loading branch information
trusktr committed Feb 13, 2015
1 parent a8cb6db commit ddcee3e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@
// global on the server, window in the browser
var root, previous_async;

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

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

0 comments on commit ddcee3e

Please sign in to comment.