elaborate underscore initialization so that it works seamlessly on CommonJS, as well as in the browser

This commit is contained in:
Jeremy Ashkenas
2009-10-28 23:53:40 -04:00
parent 4f783846de
commit a82a01ebfc
2 changed files with 22 additions and 12 deletions

View File

@@ -12,9 +12,13 @@ $(document).ready(function() {
equals(answer, 2, 'the loop broke in the middle');
var answers = [];
_.each([1, 2, 3], function(num) { answers.push(num * this.multiplier);}, {multiplier : 5});
_.each([1, 2, 3], function(num){ answers.push(num * this.multiplier);}, {multiplier : 5});
equals(answers.join(', '), '5, 10, 15', 'context object property accessed');
answers = [];
_.each("moe", function(letter){ answers.push(letter); });
equals(answers.join(', '), 'm, o, e', 'iterates over the letters in strings');
answers = [];
_.forEach([1, 2, 3], function(num){ answers.push(num); });
equals(answers.join(', '), '1, 2, 3', 'aliased as "forEach"');