summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2012-10-16 10:30:04 -0400
committerAndrew Kelley <superjoe30@gmail.com>2012-10-16 10:30:04 -0400
commit515c7dfe26135a1961ae9d71c5c4563f62c9d7b4 (patch)
tree7ccdd83be4f76fed7aaae7bf45239068bdee3b1d
parent96a7da519adc9e8cb3c187a2da4945f5edea71d3 (diff)
downloadasync-515c7dfe26135a1961ae9d71c5c4563f62c9d7b4.tar.gz
fix running in --use-strict mode. closes #189
-rw-r--r--lib/async.js8
-rw-r--r--test/test-strict.js19
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/async.js b/lib/async.js
index bbbd05c..2c79f47 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -4,8 +4,12 @@
var async = {};
// global on the server, window in the browser
- var root = this,
- previous_async = root.async;
+ var root, previous_async;
+
+ root = this;
+ if (root != null) {
+ previous_async = root.async;
+ }
async.noConflict = function () {
root.async = previous_async;
diff --git a/test/test-strict.js b/test/test-strict.js
new file mode 100644
index 0000000..39c14bf
--- /dev/null
+++ b/test/test-strict.js
@@ -0,0 +1,19 @@
+// run like this:
+// node --harmony --use-strict test-strict.js
+
+var async = require('../lib/async');
+
+function hi() {
+ let i = "abcd";
+ for (let i = 0; i < 3; i++) {
+ console.log(i);
+ }
+ console.log(i);
+}
+function hi2(){
+ console.log("blah");
+}
+
+async.parallel([hi, hi2], function() {
+ console.log("done");
+});