Skip to content

Commit

Permalink
make it strict-mode compatible; add .noConflict
Browse files Browse the repository at this point in the history
  • Loading branch information
balpha committed Dec 17, 2013
1 parent 3b5ddc7 commit 4794227
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lyfe.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* SOFTWARE.
*/

(function () {
(function (global) {

var arrIndexOf;
if (Array.prototype.indexOf) {
Expand Down Expand Up @@ -340,11 +340,16 @@
return Count(start, 1).take(len);
};

this.Generator = Generator;
var originalGenerator = global.Generator;
global.Generator = Generator;
Generator.BreakIteration = BreakIteration;
Generator.Count = Count;
Generator.Range = Range;
Generator.IterationError = IterationError;
Generator.noConflict = function () {
global.Generator = originalGenerator;
return Generator;
}

})();
})(this);

19 changes: 18 additions & 1 deletion test.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<!doctype html>
<html>
<head>
<script>
window.Generator = window.oldGenerator = {};
</script>


<script src="lyfe.js"></script>
<script>

Expand Down Expand Up @@ -43,6 +48,19 @@
var helloWorld = function () { alert("hello world"); };
var a = [13, null, helloWorld, -10.5, "lolcat"];

test("noConflict", function () {
var newGenerator = window.Generator;
if (newGenerator === oldGenerator)
return false;
var localGenerator = newGenerator.noConflict();
if (localGenerator !== newGenerator)
return false;
if (window.Generator !== oldGenerator)
return false;
window.Generator = newGenerator;
return true;
});

test("array constructor", function () {
var roundtrip = Generator(a).toArray();
return arrEqual(a, roundtrip);
Expand Down Expand Up @@ -625,7 +643,6 @@
var r2 = Generator(b).zipWithArray(a, function (x, y) { return x + y }).toArray();
return arrEqual(r1, r2);
});

</script>


Expand Down

0 comments on commit 4794227

Please sign in to comment.