diff --git a/index.html b/index.html index 66aea7125..7afa8c91c 100644 --- a/index.html +++ b/index.html @@ -121,54 +121,9 @@

-

Object-Oriented and Functional Styles

- -

- You can use Underscore in either an object-oriented or a functional style, - depending on your preference. The following two lines of code are - identical ways to double a list of numbers. -

- -
-_.map([1, 2, 3], function(n){ return n * 2; });
-_([1, 2, 3]).map(function(n){ return n * 2; });
- -

- Using the object-oriented style allows you to chain together methods. Calling - chain on a wrapped object will cause all future method calls to - return wrapped objects as well. When you've finished the computation, - use value to retrieve the final value. Here's an example of chaining - together a map/flatten/reduce, in order to get the word count of - every word in a song. -

- -
-var lyrics = [
-  {line : 1, words : "I'm a lumberjack and I'm okay"},
-  {line : 2, words : "I sleep all night and I work all day"},
-  {line : 3, words : "He's a lumberjack and he's okay"},
-  {line : 4, words : "He sleeps all night and he works all day"}
-];
-
-_(lyrics).chain()
-  .map(function(line) { return line.words.split(' '); })
-  .flatten()
-  .reduce({}, function(counts, word) {
-    counts[word] = (counts[word] || 0) + 1;
-    return counts;
-}).value();
-
-=> {lumberjack : 2, all : 4, night : 2 ... }
- -

- In addition, the - Array prototype's methods - are proxied through the chained Underscore object, so you can slip a - reverse or a push into your chain, and continue to - modify the array. -

-

Table of Contents

+ + Object-Oriented and Functional Styles

Collections @@ -217,8 +172,9 @@ _(lyrics).chain() Utility
noConflict, - identity, breakLoop, - uniqueId, template + identity, times, + breakLoop, uniqueId, + template

@@ -228,6 +184,53 @@ _(lyrics).chain()

+ +

Object-Oriented and Functional Styles

+ +

+ You can use Underscore in either an object-oriented or a functional style, + depending on your preference. The following two lines of code are + identical ways to double a list of numbers. +

+ +
+_.map([1, 2, 3], function(n){ return n * 2; });
+_([1, 2, 3]).map(function(n){ return n * 2; });
+ +

+ Using the object-oriented style allows you to chain together methods. Calling + chain on a wrapped object will cause all future method calls to + return wrapped objects as well. When you've finished the computation, + use value to retrieve the final value. Here's an example of chaining + together a map/flatten/reduce, in order to get the word count of + every word in a song. +

+ +
+var lyrics = [
+  {line : 1, words : "I'm a lumberjack and I'm okay"},
+  {line : 2, words : "I sleep all night and I work all day"},
+  {line : 3, words : "He's a lumberjack and he's okay"},
+  {line : 4, words : "He sleeps all night and he works all day"}
+];
+
+_(lyrics).chain()
+  .map(function(line) { return line.words.split(' '); })
+  .flatten()
+  .reduce({}, function(counts, word) {
+    counts[word] = (counts[word] || 0) + 1;
+    return counts;
+}).value();
+
+=> {lumberjack : 2, all : 4, night : 2 ... }
+ +

+ In addition, the + Array prototype's methods + are proxied through the chained Underscore object, so you can slip a + reverse or a push into your chain, and continue to + modify the array. +

Collection Functions (Arrays or Objects)

@@ -955,6 +958,14 @@ var moe = {name : 'moe'}; moe === _.identity(moe); => true +

+ times_.times(n, iterator) +
+ Invokes the given iterator function n times. +

+
+_(3).times(function(){ genie.grantWish(); });
+

breakLoop_.breakLoop()