@@ -108,18 +108,16 @@ <h1>Underscore.js</h1>
108
108
109
109
< h2 > Downloads < i style ="padding-left: 12px; font-size:12px; "> (Right-click, and use "Save As")</ i > </ h2 >
110
110
111
- < p >
112
- < table >
113
- < tr >
114
- < td > < a href ="underscore.js "> Development Version (1.0.3)</ a > </ td >
115
- < td > < i > 24kb, Uncompressed with Comments</ i > </ td >
116
- </ tr >
117
- < tr >
118
- < td > < a href ="underscore-min.js "> Production Version (1.0.3)</ a > </ td >
119
- < td > < i > 2.9kb, Packed and Gzipped</ i > </ td >
120
- </ tr >
121
- </ table >
122
- </ p >
111
+ < table >
112
+ < tr >
113
+ < td > < a href ="underscore.js "> Development Version (1.0.4)</ a > </ td >
114
+ < td > < i > 24kb, Uncompressed with Comments</ i > </ td >
115
+ </ tr >
116
+ < tr >
117
+ < td > < a href ="underscore-min.js "> Production Version (1.0.4)</ a > </ td >
118
+ < td > < i > 2.9kb, Packed and Gzipped</ i > </ td >
119
+ </ tr >
120
+ </ table >
123
121
124
122
< h2 > Table of Contents</ h2 >
125
123
@@ -144,15 +142,16 @@ <h2>Table of Contents</h2>
144
142
< br />
145
143
< span class ="methods "> < a href ="#first "> first</ a > , < a href ="#rest "> rest</ a > , < a href ="#last "> last</ a > ,
146
144
< a href ="#compact "> compact</ a > , < a href ="#flatten "> flatten</ a > , < a href ="#without "> without</ a > , < a href ="#uniq "> uniq</ a > ,
147
- < a href ="#intersect "> intersect</ a > , < a href ="#zip "> zip</ a > , < a href ="#indexOf "> indexOf</ a > </ span > ,
145
+ < a href ="#intersect "> intersect</ a > , < a href ="#zip "> zip</ a > , < a href ="#indexOf "> indexOf</ a > ,
148
146
< a href ="#lastIndexOf "> lastIndexOf</ a > , < a href ="#range "> range</ a > </ span >
149
147
</ p >
150
148
151
149
< p >
152
150
< b > Functions</ b >
153
151
< br />
154
- < span class ="methods "> < a href ="#bind "> bind</ a > , < a href ="#bindAll "> bindAll</ a > , < a href ="#delay "> delay</ a > ,
155
- < a href ="#defer "> defer</ a > , < a href ="#wrap "> wrap</ a > </ span > , < a href ="#compose "> compose</ a > </ span >
152
+ < span class ="methods "> < a href ="#bind "> bind</ a > , < a href ="#bindAll "> bindAll</ a > ,
153
+ < a href ="#memoize "> memoize</ a > , < a href ="#delay "> delay</ a > , < a href ="#defer "> defer</ a > ,
154
+ < a href ="#wrap "> wrap</ a > , < a href ="#compose "> compose</ a > </ span >
156
155
</ p >
157
156
158
157
< p >
@@ -173,7 +172,7 @@ <h2>Table of Contents</h2>
173
172
< br />
174
173
< span class ="methods "> < a href ="#noConflict "> noConflict</ a > ,
175
174
< a href ="#identity "> identity</ a > , < a href ="#times "> times</ a > ,
176
- < a href ="#breakLoop "> breakLoop</ a > </ span > , < a href ="#mixin "> mixin</ a > </ span > ,
175
+ < a href ="#breakLoop "> breakLoop</ a > , < a href ="#mixin "> mixin</ a > ,
177
176
< a href ="#uniqueId "> uniqueId</ a > , < a href ="#template "> template</ a > </ span >
178
177
</ p >
179
178
@@ -652,6 +651,21 @@ <h2>Function (uh, ahem) Functions</h2>
652
651
_.bindAll(buttonView);
653
652
jQuery('#underscore_button').bind('click', buttonView.onClick);
654
653
=> When the button is clicked, this.label will have the correct value...
654
+ </ pre >
655
+
656
+ < p id ="memoize ">
657
+ < b class ="header "> memoize</ b > < code > _.memoize(function, [hashFunction])</ code >
658
+ < br />
659
+ Memoizes a given < b > function</ b > by caching the computed result. Useful
660
+ for speeding up slow-running computations. If passed an optional
661
+ < b > hashFunction</ b > , it will be used to compute the hash key for storing
662
+ the result, based on the arguments to the original function.
663
+ </ p >
664
+ < pre >
665
+ var fibonacci = function(n) {
666
+ return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
667
+ };
668
+ var fastFibonacci = _.memoize(fibonacci);
655
669
</ pre >
656
670
657
671
< p id ="delay ">
@@ -1136,6 +1150,12 @@ <h2>Links & Suggested Reading</h2>
1136
1150
1137
1151
< h2 > Change Log</ h2 >
1138
1152
1153
+ < p >
1154
+ < b class ="header "> 1.0.4</ b > < br />
1155
+ Andri Möll contributed the < tt > _.memoize</ tt > function, which can be
1156
+ used to speed up expensive repeated computations by caching the results.
1157
+ </ p >
1158
+
1139
1159
< p >
1140
1160
< b class ="header "> 1.0.3</ b > < br />
1141
1161
Patch that makes < tt > _.isEqual</ tt > return < tt > false</ tt > if any property
0 commit comments