PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/index.html

https://github.com/rfletcher/underscore
HTML | 1291 lines | 1156 code | 135 blank | 0 comment | 0 complexity | c980b041158af632c0cb6c235143c2d2 MD5 | raw file
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="chrome=1">
  6. <title>Underscore.js</title>
  7. <style>
  8. body {
  9. font-size: 16px;
  10. line-height: 24px;
  11. background: #f0f0e5;
  12. color: #252519;
  13. font-family: "Palatino Linotype", "Book Antiqua", Palatino, FreeSerif, serif;
  14. }
  15. div.container {
  16. width: 720px;
  17. margin: 50px 0 50px 50px;
  18. }
  19. p {
  20. width: 550px;
  21. }
  22. #documentation p {
  23. margin-bottom: 4px;
  24. }
  25. a, a:visited {
  26. padding: 0 2px;
  27. text-decoration: none;
  28. background: #dadaba;
  29. color: #252519;
  30. }
  31. a:active, a:hover {
  32. color: #000;
  33. background: #f0c095;
  34. }
  35. h1, h2, h3, h4, h5, h6 {
  36. margin-top: 40px;
  37. }
  38. b.header {
  39. font-size: 18px;
  40. }
  41. span.alias {
  42. font-size: 14px;
  43. font-style: italic;
  44. margin-left: 20px;
  45. }
  46. table, tr, td {
  47. margin: 0; padding: 0;
  48. }
  49. td {
  50. padding: 2px 12px 2px 0;
  51. }
  52. code, pre, tt {
  53. font-family: Monaco, Consolas, "Lucida Console", monospace;
  54. font-size: 12px;
  55. line-height: 18px;
  56. color: #555529;
  57. }
  58. code {
  59. margin-left: 20px;
  60. }
  61. pre {
  62. font-size: 12px;
  63. padding: 2px 0 2px 12px;
  64. border-left: 6px solid #aaaa99;
  65. margin: 0px 0 30px;
  66. }
  67. </style>
  68. </head>
  69. <body>
  70. <div class="container">
  71. <h1>Underscore.js</h1>
  72. <p>
  73. <a href="http://github.com/documentcloud/underscore/">Underscore</a> is a
  74. utility-belt library for JavaScript that provides a lot of the
  75. functional programming support that you would expect in
  76. <a href="http://prototypejs.org/api">Prototype.js</a>
  77. (or <a href="http://www.ruby-doc.org/core/classes/Enumerable.html">Ruby</a>),
  78. but without extending any of the built-in JavaScript objects. It's the
  79. tie to go along with <a href="http://docs.jquery.com">jQuery</a>'s tux.
  80. </p>
  81. <p>
  82. Underscore provides 60-odd functions that support both the usual
  83. functional suspects: <b>map</b>, <b>select</b>, <b>invoke</b> &mdash;
  84. as well as more specialized helpers: function binding, javascript
  85. templating, deep equality testing, and so on. It delegates to built-in
  86. functions, if present, so modern browsers will use the
  87. native implementations of <b>forEach</b>, <b>map</b>, <b>reduce</b>,
  88. <b>filter</b>, <b>every</b>, <b>some</b> and <b>indexOf</b>.
  89. </p>
  90. <p>
  91. A complete <a href="test/test.html">Test &amp; Benchmark Suite</a>
  92. is included for your perusal.
  93. </p>
  94. <p>
  95. The unabridged source code is
  96. <a href="http://github.com/documentcloud/underscore/">available on GitHub</a>.
  97. </p>
  98. <p>
  99. <i>Underscore is an open-source component of <a href="http://documentcloud.org/">DocumentCloud</a>.</i>
  100. </p>
  101. <h2>Downloads <i style="padding-left: 12px; font-size:12px;">(Right-click, and use "Save As")</i></h2>
  102. <p>
  103. <table>
  104. <tr>
  105. <td><a href="underscore.js">Development Version (0.5.8)</a></td>
  106. <td><i>22kb, Uncompressed with Comments</i></td>
  107. </tr>
  108. <tr>
  109. <td><a href="underscore-min.js">Production Version (0.5.8)</a></td>
  110. <td><i>3kb, Packed and Gzipped</i></td>
  111. </tr>
  112. </table>
  113. </p>
  114. <h2 id="styles">Object-Oriented and Functional Styles</h2>
  115. <p>
  116. You can use Underscore in either an object-oriented or a functional style,
  117. depending on your preference. The following two lines of code are
  118. identical ways to double a list of numbers.
  119. </p>
  120. <pre>
  121. _.map([1, 2, 3], function(n){ return n * 2; });
  122. _([1, 2, 3]).map(function(n){ return n * 2; });</pre>
  123. <p>
  124. Using the object-oriented style allows you to chain together methods. Calling
  125. <tt>chain</tt> on a wrapped object will cause all future method calls to
  126. return wrapped objects as well. When you've finished the computation,
  127. use <tt>value</tt> to retrieve the final value. Here's an example of chaining
  128. together a <b>map/flatten/reduce</b>, in order to get the word count of
  129. every word in a song.
  130. </p>
  131. <pre>
  132. var lyrics = [
  133. {line : 1, words : "I'm a lumberjack and I'm okay"},
  134. {line : 2, words : "I sleep all night and I work all day"},
  135. {line : 3, words : "He's a lumberjack and he's okay"},
  136. {line : 4, words : "He sleeps all night and he works all day"}
  137. ];
  138. _(lyrics).chain()
  139. .map(function(line) { return line.words.split(' '); })
  140. .flatten()
  141. .reduce({}, function(counts, word) {
  142. counts[word] = (counts[word] || 0) + 1;
  143. return counts;
  144. }).value();
  145. =&gt; {lumberjack : 2, all : 4, night : 2 ... }</pre>
  146. <p>
  147. In addition, the
  148. <a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/Array">Array prototype's methods</a>
  149. are proxied through the chained Underscore object, so you can slip a
  150. <tt>reverse</tt> or a <tt>push</tt> into your chain, and continue to
  151. modify the array.
  152. </p>
  153. <h2>Table of Contents</h2>
  154. <p>
  155. <b>Collections</b>
  156. <br />
  157. <span class="methods"><a href="#each">each</a>, <a href="#map">map</a>,
  158. <a href="#reduce">reduce</a>, <a href="#reduceRight">reduceRight</a>,
  159. <a href="#detect">detect</a>, <a href="#select">select</a>,
  160. <a href="#reject">reject</a>, <a href="#all">all</a>,
  161. <a href="#any">any</a>, <a href="#include">include</a>,
  162. <a href="#invoke">invoke</a>, <a href="#pluck">pluck</a>,
  163. <a href="#max">max</a>, <a href="#min">min</a>,
  164. <a href="#sortBy">sortBy</a>, <a href="#sortedIndex">sortedIndex</a>,
  165. <a href="#toArray">toArray</a>, <a href="#size">size</a></span>
  166. </p>
  167. <p>
  168. <b>Arrays</b>
  169. <br />
  170. <span class="methods"><a href="#first">first</a>, <a href="#rest">rest</a>, <a href="#last">last</a>,
  171. <a href="#compact">compact</a>, <a href="#flatten">flatten</a>, <a href="#without">without</a>, <a href="#uniq">uniq</a>,
  172. <a href="#intersect">intersect</a>, <a href="#zip">zip</a>, <a href="#indexOf">indexOf</a></span>,
  173. <a href="#lastIndexOf">lastIndexOf</a>, <a href="#range">range</a></span>
  174. </p>
  175. <p>
  176. <b>Functions</b>
  177. <br />
  178. <span class="methods"><a href="#bind">bind</a>, <a href="#bindAll">bindAll</a>, <a href="#delay">delay</a>,
  179. <a href="#defer">defer</a>, <a href="#wrap">wrap</a></span>, <a href="#compose">compose</a></span>
  180. </p>
  181. <p>
  182. <b>Objects</b>
  183. <br />
  184. <span class="methods"><a href="#keys">keys</a>, <a href="#values">values</a>,
  185. <a href="#functions">functions</a>, <a href="#extend">extend</a>, <a href="#clone">clone</a>, <a href="#tap">tap</a>,
  186. <a href="#isEqual">isEqual</a>, <a href="#isEmpty">isEmpty</a>, <a href="#isElement">isElement</a>,
  187. <a href="#isArray">isArray</a>, <a href="#isArguments">isArguments</a>, <a href="#isFunction">isFunction</a>, <a href="#isString">isString</a>,
  188. <a href="#isNumber">isNumber</a>, <a href="#isDate">isDate</a>, <a href="#isRegExp">isRegExp</a>
  189. <a href="#isNaN">isNaN</a>, <a href="#isNull">isNull</a>,
  190. <a href="#isUndefined">isUndefined</a>
  191. </span>
  192. </p>
  193. <p>
  194. <b>Utility</b>
  195. <br />
  196. <span class="methods"><a href="#noConflict">noConflict</a>,
  197. <a href="#identity">identity</a>, <a href="#breakLoop">breakLoop</a></span>,
  198. <a href="#uniqueId">uniqueId</a>, <a href="#template">template</a></span>
  199. </p>
  200. <p>
  201. <b>Chaining</b>
  202. <br />
  203. <span class="methods"><a href="#chain">chain</a>, <a href="#value">value</a>
  204. </p>
  205. <div id="documentation">
  206. <h2>Collection Functions (Arrays or Objects)</h2>
  207. <p id="each">
  208. <b class="header">each</b><code>_.each(list, iterator, [context])</code>
  209. <span class="alias">Alias: <b>forEach</b></span>
  210. <br />
  211. Iterates over a <b>list</b> of elements, yielding each in turn to an <b>iterator</b>
  212. function. The <b>iterator</b> is bound to the <b>context</b> object, if one is
  213. passed. Each invocation of <b>iterator</b> is called with three arguments:
  214. <tt>(element, index, list)</tt>. If <b>list</b> is a JavaScript object, <b>iterator</b>'s
  215. arguments will be <tt>(value, key, list)</tt>. Use <a href="#breakLoop"><tt>breakLoop</tt></a>
  216. to break out of the iteration. Delegates to the native
  217. <b>forEach</b> function if it exists.
  218. </p>
  219. <pre>
  220. _.each([1, 2, 3], function(num){ alert(num); });
  221. =&gt; alerts each number in turn...</pre>
  222. <p id="map">
  223. <b class="header">map</b><code>_.map(list, iterator, [context])</code>
  224. <br />
  225. Produces a new array of values by mapping each value in <b>list</b>
  226. through a transformation function (<b>iterator</b>). If the native
  227. <b>map</b> method exists, it will be used instead.
  228. </p>
  229. <pre>
  230. _.map([1, 2, 3], function(num){ return num * 3 });
  231. =&gt; [3, 6, 9]</pre>
  232. <p id="reduce">
  233. <b class="header">reduce</b><code>_.reduce(list, memo, iterator, [context])</code>
  234. <span class="alias">Aliases: <b>inject, foldl</b></span>
  235. <br />
  236. Also known as <b>inject</b> and <b>foldl</b>, <b>reduce</b> boils down a
  237. <b>list</b> of values into a single value. <b>Memo</b> is the initial state
  238. of the reduction, and each successive step of it should be returned by
  239. <b>iterator</b>.
  240. </p>
  241. <pre>
  242. var sum = _.reduce([1, 2, 3], 0, function(memo, num){ return memo + num });
  243. =&gt; 6
  244. </pre>
  245. <p id="reduceRight">
  246. <b class="header">reduceRight</b><code>_.reduceRight(list, memo, iterator, [context])</code>
  247. <span class="alias">Alias: <b>foldr</b></span>
  248. <br />
  249. The right-associative version of <b>reduce</b>. Delegates to the
  250. JavaScript 1.8 version of <b>reduceRight</b>, if it exists. <b>Foldr</b>
  251. is not as useful in JavaScript as it would be in a language with lazy
  252. evaluation.
  253. </p>
  254. <pre>
  255. var list = [[0, 1], [2, 3], [4, 5]];
  256. var flat = _.reduceRight(list, [], function(a, b) { return a.concat(b); });
  257. =&gt; [4, 5, 2, 3, 0, 1]
  258. </pre>
  259. <p id="detect">
  260. <b class="header">detect</b><code>_.detect(list, iterator, [context])</code>
  261. <br />
  262. Looks through each value in the <b>list</b>, returning the first one that
  263. passes a truth test (<b>iterator</b>). The function returns as
  264. soon as it finds an acceptable element, and doesn't traverse the
  265. entire list.
  266. </p>
  267. <pre>
  268. var even = _.detect([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
  269. =&gt; 2
  270. </pre>
  271. <p id="select">
  272. <b class="header">select</b><code>_.select(list, iterator, [context])</code>
  273. <span class="alias">Alias: <b>filter</b></span>
  274. <br />
  275. Looks through each value in the <b>list</b>, returning an array of all
  276. the values that pass a truth test (<b>iterator</b>). Delegates to the
  277. native <b>filter</b> method, if it exists.
  278. </p>
  279. <pre>
  280. var evens = _.select([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
  281. =&gt; [2, 4, 6]
  282. </pre>
  283. <p id="reject">
  284. <b class="header">reject</b><code>_.reject(list, iterator, [context])</code>
  285. <br />
  286. Returns the values in <b>list</b> without the elements that the truth
  287. test (<b>iterator</b>) passes. The opposite of <b>select</b>.
  288. </p>
  289. <pre>
  290. var odds = _.reject([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
  291. =&gt; [1, 3, 5]
  292. </pre>
  293. <p id="all">
  294. <b class="header">all</b><code>_.all(list, [iterator], [context])</code>
  295. <span class="alias">Alias: <b>every</b></span>
  296. <br />
  297. Returns <i>true</i> if all of the values in the <b>list</b> pass the <b>iterator</b>
  298. truth test. If an <b>iterator</b> is not provided, the truthy value of
  299. the element will be used instead. Delegates to the native method <b>every</b>, if
  300. present.
  301. </p>
  302. <pre>
  303. _.all([true, 1, null, 'yes']);
  304. =&gt; false
  305. </pre>
  306. <p id="any">
  307. <b class="header">any</b><code>_.any(list, [iterator], [context])</code>
  308. <span class="alias">Alias: <b>some</b></span>
  309. <br />
  310. Returns <i>true</i> if any of the values in the <b>list</b> pass the
  311. <b>iterator</b> truth test. Short-circuits and stops traversing the list
  312. if a true element is found. Delegates to the native method <b>some</b>,
  313. if present.
  314. </p>
  315. <pre>
  316. _.any([null, 0, 'yes', false]);
  317. =&gt; true
  318. </pre>
  319. <p id="include">
  320. <b class="header">include</b><code>_.include(list, value)</code>
  321. <br />
  322. Returns <i>true</i> if the <b>value</b> is present in the <b>list</b>, using
  323. <i>===</i> to test equality. Uses <b>indexOf</b> internally, if <b>list</b>
  324. is an Array.
  325. </p>
  326. <pre>
  327. _.include([1, 2, 3], 3);
  328. =&gt; true
  329. </pre>
  330. <p id="invoke">
  331. <b class="header">invoke</b><code>_.invoke(list, methodName, [*arguments])</code>
  332. <br />
  333. Calls the method named by <b>methodName</b> on each value in the <b>list</b>.
  334. Any extra arguments passed to <b>invoke</b> will be forwarded on to the
  335. method invocation.
  336. </p>
  337. <pre>
  338. _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
  339. =&gt; [[1, 5, 7], [1, 2, 3]]
  340. </pre>
  341. <p id="pluck">
  342. <b class="header">pluck</b><code>_.pluck(list, propertyName)</code>
  343. <br />
  344. An convenient version of what is perhaps the most common use-case for
  345. <b>map</b>: extracting a list of property values.
  346. </p>
  347. <pre>
  348. var stooges = [{name : 'moe', age : 40}, {name : 'larry', age : 50}, {name : 'curly', age : 60}];
  349. _.pluck(stooges, 'name');
  350. =&gt; ["moe", "larry", "curly"]
  351. </pre>
  352. <p id="max">
  353. <b class="header">max</b><code>_.max(list, [iterator], [context])</code>
  354. <br />
  355. Returns the maximum value in <b>list</b>. If <b>iterator</b> is passed,
  356. it will be used on each value to generate the criterion by which the
  357. value is ranked.
  358. </p>
  359. <pre>
  360. var stooges = [{name : 'moe', age : 40}, {name : 'larry', age : 50}, {name : 'curly', age : 60}];
  361. _.max(stooges, function(stooge){ return stooge.age; });
  362. =&gt; {name : 'curly', age : 60};
  363. </pre>
  364. <p id="min">
  365. <b class="header">min</b><code>_.min(list, [iterator], [context])</code>
  366. <br />
  367. Returns the minimum value in <b>list</b>. If <b>iterator</b> is passed,
  368. it will be used on each value to generate the criterion by which the
  369. value is ranked.
  370. </p>
  371. <pre>
  372. var numbers = [10, 5, 100, 2, 1000];
  373. _.min(numbers);
  374. =&gt; 2
  375. </pre>
  376. <p id="sortBy">
  377. <b class="header">sortBy</b><code>_.sortBy(list, iterator, [context])</code>
  378. <br />
  379. Returns a sorted <b>list</b>, ranked by the results of running each
  380. value through <b>iterator</b>.
  381. </p>
  382. <pre>
  383. _.sortBy([1, 2, 3, 4, 5, 6], function(num){ return Math.sin(num); });
  384. =&gt; [5, 4, 6, 3, 1, 2]
  385. </pre>
  386. <p id="sortedIndex">
  387. <b class="header">sortedIndex</b><code>_.sortedIndex(list, value, [iterator])</code>
  388. <br />
  389. Uses a binary search to determine the index at which the <b>value</b>
  390. should be inserted into the <b>list</b> in order to maintain the <b>list</b>'s
  391. sorted order. If an <b>iterator</b> is passed, it will be used to compute
  392. the sort ranking of each value.
  393. </p>
  394. <pre>
  395. _.sortedIndex([10, 20, 30, 40, 50], 35);
  396. =&gt; 3
  397. </pre>
  398. <p id="toArray">
  399. <b class="header">toArray</b><code>_.toArray(list)</code>
  400. <br />
  401. Converts the <b>list</b> (anything that can be iterated over), into a
  402. real Array. Useful for transmuting the <b>arguments</b> object.
  403. </p>
  404. <pre>
  405. (function(){ return _.toArray(arguments).slice(0); })(1, 2, 3);
  406. =&gt; [1, 2, 3]
  407. </pre>
  408. <p id="size">
  409. <b class="header">size</b><code>_.size(list)</code>
  410. <br />
  411. Return the number of values in the <b>list</b>.
  412. </p>
  413. <pre>
  414. _.size({one : 1, two : 2, three : 3});
  415. =&gt; 3
  416. </pre>
  417. <h2>Array Functions</h2>
  418. <p>
  419. <i>Note: All array functions will also work on the <b>arguments</b> object.</i>
  420. </p>
  421. <p id="first">
  422. <b class="header">first</b><code>_.first(array, [n])</code>
  423. <span class="alias">Alias: <b>head</b></span>
  424. <br />
  425. Returns the first element of an <b>array</b>. Passing <b>n</b> will
  426. return the first <b>n</b> elements of the array.
  427. </p>
  428. <pre>
  429. _.first([5, 4, 3, 2, 1]);
  430. =&gt; 5
  431. </pre>
  432. <p id="rest">
  433. <b class="header">rest</b><code>_.rest(array, [index])</code>
  434. <span class="alias">Alias: <b>tail</b></span>
  435. <br />
  436. Returns the <b>rest</b> of the elements in an array. Pass an <b>index</b>
  437. to return the values of the array from that index onward.
  438. </p>
  439. <pre>
  440. _.rest([5, 4, 3, 2, 1]);
  441. =&gt; [4, 3, 2, 1]
  442. </pre>
  443. <p id="last">
  444. <b class="header">last</b><code>_.last(array)</code>
  445. <br />
  446. Returns the last element of an <b>array</b>.
  447. </p>
  448. <pre>
  449. _.last([5, 4, 3, 2, 1]);
  450. =&gt; 1
  451. </pre>
  452. <p id="compact">
  453. <b class="header">compact</b><code>_.compact(array)</code>
  454. <br />
  455. Returns a copy of the <b>array</b> with all falsy values removed.
  456. In JavaScript, <i>false</i>, <i>null</i>, <i>0</i>, <i>""</i>,
  457. <i>undefined</i> and <i>NaN</i> are all falsy.
  458. </p>
  459. <pre>
  460. _.compact([0, 1, false, 2, '', 3]);
  461. =&gt; [1, 2, 3]
  462. </pre>
  463. <p id="flatten">
  464. <b class="header">flatten</b><code>_.flatten(array)</code>
  465. <br />
  466. Flattens a nested <b>array</b> (the nesting can be to any depth).
  467. </p>
  468. <pre>
  469. _.flatten([1, [2], [3, [[[4]]]]]);
  470. =&gt; [1, 2, 3, 4];
  471. </pre>
  472. <p id="without">
  473. <b class="header">without</b><code>_.without(array, [*values])</code>
  474. <br />
  475. Returns a copy of the <b>array</b> with all instances of the <b>values</b>
  476. removed. <i>===</i> is used for the equality test.
  477. </p>
  478. <pre>
  479. _.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
  480. =&gt; [2, 3, 4]
  481. </pre>
  482. <p id="uniq">
  483. <b class="header">uniq</b><code>_.uniq(array, [isSorted])</code>
  484. <br />
  485. Produces a duplicate-free version of the <b>array</b>, using <i>===</i> to test
  486. object equality. If you know in advance that the <b>array</b> is sorted,
  487. passing <i>true</i> for <b>isSorted</b> will run a much faster algorithm.
  488. </p>
  489. <pre>
  490. _.uniq([1, 2, 1, 3, 1, 4]);
  491. =&gt; [1, 2, 3, 4]
  492. </pre>
  493. <p id="intersect">
  494. <b class="header">intersect</b><code>_.intersect(*arrays)</code>
  495. <br />
  496. Computes the list of values that are the intersection of all the <b>arrays</b>.
  497. Each value in the result is present in each of the <b>arrays</b>.
  498. </p>
  499. <pre>
  500. _.intersect([1, 2, 3], [101, 2, 1, 10], [2, 1]);
  501. =&gt; [1, 2]
  502. </pre>
  503. <p id="zip">
  504. <b class="header">zip</b><code>_.zip(*arrays)</code>
  505. <br />
  506. Merges together the values of each of the <b>arrays</b> with the
  507. values at the corresponding position. Useful when you have separate
  508. data sources that are coordinated through matching array indexes.
  509. </p>
  510. <pre>
  511. _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]);
  512. =&gt; [["moe", 30, true], ["larry", 40, false], ["curly", 50, false]]
  513. </pre>
  514. <p id="indexOf">
  515. <b class="header">indexOf</b><code>_.indexOf(array, value)</code>
  516. <br />
  517. Returns the index at which <b>value</b> can be found in the <b>array</b>,
  518. or <i>-1</i> if value is not present in the <b>array</b>. Uses the native
  519. <b>indexOf</b> function unless it's missing.
  520. </p>
  521. <pre>
  522. _.indexOf([1, 2, 3], 2);
  523. =&gt; 1
  524. </pre>
  525. <p id="lastIndexOf">
  526. <b class="header">lastIndexOf</b><code>_.lastIndexOf(array, value)</code>
  527. <br />
  528. Returns the index of the last occurrence of <b>value</b> in the <b>array</b>,
  529. or <i>-1</i> if value is not present. Uses the native <b>lastIndexOf</b>
  530. function if possible.
  531. </p>
  532. <pre>
  533. _.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
  534. =&gt; 4
  535. </pre>
  536. <p id="range">
  537. <b class="header">range</b><code>_.range([start], stop, [step])</code>
  538. <br />
  539. A function to create flexibly-numbered lists of integers, handy for
  540. <tt>each</tt> and <tt>map</tt> loops. <b>start</b>, if omitted, defaults
  541. to <i>0</i>; <b>step</b> defaults to <i>1</i>. Returns a list of integers
  542. from <b>start</b> to <b>stop</b>, incremented (or decremented) by <b>step</b>,
  543. exclusive.
  544. </p>
  545. <pre>
  546. _.range(10);
  547. =&gt; [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  548. _.range(1, 11);
  549. =&gt; [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  550. _.range(0, 30, 5);
  551. =&gt; [0, 5, 10, 15, 20, 25]
  552. _.range(0, -10, -1);
  553. =&gt; [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
  554. _.range(0);
  555. =&gt; []
  556. </pre>
  557. <h2>Function (uh, ahem) Functions</h2>
  558. <p id="bind">
  559. <b class="header">bind</b><code>_.bind(function, object, [*arguments])</code>
  560. <br />
  561. Bind a <b>function</b> to an <b>object</b>, meaning that whenever
  562. the function is called, the value of <i>this</i> will be the <b>object</b>.
  563. Optionally, bind <b>arguments</b> to the <b>function</b> to pre-fill them,
  564. also known as <b>currying</b>.
  565. </p>
  566. <pre>
  567. var func = function(greeting){ return greeting + ': ' + this.name };
  568. func = _.bind(func, {name : 'moe'}, 'hi');
  569. func();
  570. =&gt; 'hi: moe'
  571. </pre>
  572. <p id="bindAll">
  573. <b class="header">bindAll</b><code>_.bindAll(object, [*methodNames])</code>
  574. <br />
  575. Binds a number of methods on the <b>object</b>, specified by
  576. <b>methodNames</b>, to be run in the context of that object whenever they
  577. are invoked. Very handy for binding functions that are going to be used
  578. as event handlers, which would otherwise be invoked with a fairly useless
  579. <i>this</i>. If no <b>methodNames</b> are provided, all of the object's
  580. function properties will be bound to it.
  581. </p>
  582. <pre>
  583. var buttonView = {
  584. label : 'underscore',
  585. onClick : function(){ alert('clicked: ' + this.label); },
  586. onHover : function(){ console.log('hovering: ' + this.label); }
  587. };
  588. _.bindAll(buttonView);
  589. jQuery('#underscore_button').bind('click', buttonView.onClick);
  590. =&gt; When the button is clicked, this.label will have the correct value...
  591. </pre>
  592. <p id="delay">
  593. <b class="header">delay</b><code>_.delay(function, wait, [*arguments])</code>
  594. <br />
  595. Much like <b>setTimeout</b>, invokes <b>function</b> after <b>wait</b>
  596. milliseconds. If you pass the optional <b>arguments</b>, they will be
  597. forwarded on to the <b>function</b> when it is invoked.
  598. </p>
  599. <pre>
  600. var log = _.bind(console.log, console);
  601. _.delay(log, 1000, 'logged later');
  602. =&gt; 'logged later' // Appears after one second.
  603. </pre>
  604. <p id="defer">
  605. <b class="header">defer</b><code>_.defer(function)</code>
  606. <br />
  607. Defers invoking the <b>function</b> until the current call stack has cleared,
  608. similar to using <b>setTimeout</b> with a delay of 0. Useful for performing
  609. expensive computations or HTML rendering in chunks without blocking the UI thread
  610. from updating.
  611. </p>
  612. <pre>
  613. _.defer(function(){ alert('deferred'); });
  614. // Returns from the function before the alert runs.
  615. </pre>
  616. <p id="wrap">
  617. <b class="header">wrap</b><code>_.wrap(function, wrapper)</code>
  618. <br />
  619. Wraps the first <b>function</b> inside of the <b>wrapper</b> function,
  620. passing it as the first argument. This allows the <b>wrapper</b> to
  621. execute code before and after the <b>function</b> runs, adjust the arguments,
  622. and execute it conditionally.
  623. </p>
  624. <pre>
  625. var hello = function(name) { return "hello: " + name; };
  626. hello = _.wrap(hello, function(func) {
  627. return "before, " + func("moe") + ", after";
  628. });
  629. hello();
  630. =&gt; 'before, hello: moe, after'
  631. </pre>
  632. <p id="compose">
  633. <b class="header">compose</b><code>_.compose(*functions)</code>
  634. <br />
  635. Returns the composition of a list of <b>functions</b>, where each function
  636. consumes the return value of the function that follows. In math terms,
  637. composing the functions <i>f()</i>, <i>g()</i>, and <i>h()</i> produces
  638. <i>f(g(h()))</i>.
  639. </p>
  640. <pre>
  641. var greet = function(name){ return "hi: " + name; };
  642. var exclaim = function(statement){ return statement + "!"; };
  643. var welcome = _.compose(greet, exclaim);
  644. welcome('moe');
  645. =&gt; 'hi: moe!'
  646. </pre>
  647. <h2>Object Functions</h2>
  648. <p id="keys">
  649. <b class="header">keys</b><code>_.keys(object)</code>
  650. <br />
  651. Retrieve all the names of the <b>object</b>'s properties.
  652. </p>
  653. <pre>
  654. _.keys({one : 1, two : 2, three : 3});
  655. =&gt; ["one", "two", "three"]
  656. </pre>
  657. <p id="values">
  658. <b class="header">values</b><code>_.values(object)</code>
  659. <br />
  660. Return all of the values of the <b>object</b>'s properties.
  661. </p>
  662. <pre>
  663. _.values({one : 1, two : 2, three : 3});
  664. =&gt; [1, 2, 3]
  665. </pre>
  666. <p id="functions">
  667. <b class="header">functions</b><code>_.functions(object)</code>
  668. <span class="alias">Alias: <b>methods</b></span>
  669. <br />
  670. Returns a sorted list of the names of every method in an object &mdash;
  671. that is to say, the name of every function property of the object.
  672. </p>
  673. <pre>
  674. _.functions(_);
  675. =&gt; ["all", "any", "bind", "bindAll", "clone", "compact", "compose" ...
  676. </pre>
  677. <p id="extend">
  678. <b class="header">extend</b><code>_.extend(destination, source)</code>
  679. <br />
  680. Copy all of the properties in the <b>source</b> object over to the
  681. <b>destination</b> object.
  682. </p>
  683. <pre>
  684. _.extend({name : 'moe'}, {age : 50});
  685. =&gt; {name : 'moe', age : 50}
  686. </pre>
  687. <p id="clone">
  688. <b class="header">clone</b><code>_.clone(object)</code>
  689. <br />
  690. Create a shallow-copied clone of the <b>object</b>. Any nested objects
  691. or arrays will be copied by reference, not duplicated.
  692. </p>
  693. <pre>
  694. _.clone({name : 'moe'});
  695. =&gt; {name : 'moe'};
  696. </pre>
  697. <p id="tap">
  698. <b class="header">tap</b><code>_.tap(object, interceptor)</code>
  699. <br />
  700. Invokes <b>interceptor</b> with the <b>object</b>, and then returns <b>object</b>.
  701. The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
  702. </p>
  703. <pre>
  704. _([1,2,3,200]).chain().
  705. select(function(num) { return num % 2 == 0; }).
  706. tap(console.log).
  707. map(function(num) { return num * num }).
  708. value();
  709. =&gt; [2, 200]
  710. =&gt; [4, 40000]
  711. </pre>
  712. <p id="isEqual">
  713. <b class="header">isEqual</b><code>_.isEqual(object, other)</code>
  714. <br />
  715. Performs an optimized deep comparison between the two objects, to determine
  716. if they should be considered equal.
  717. </p>
  718. <pre>
  719. var moe = {name : 'moe', luckyNumbers : [13, 27, 34]};
  720. var clone = {name : 'moe', luckyNumbers : [13, 27, 34]};
  721. moe == clone;
  722. =&gt; false
  723. _.isEqual(moe, clone);
  724. =&gt; true
  725. </pre>
  726. <p id="isEmpty">
  727. <b class="header">isEmpty</b><code>_.isEmpty(object)</code>
  728. <br />
  729. Returns <i>true</i> if <b>object</b> contains no values.
  730. </p>
  731. <pre>
  732. _.isEmpty([1, 2, 3]);
  733. =&gt; false
  734. _.isEmpty({});
  735. =&gt; true
  736. </pre>
  737. <p id="isElement">
  738. <b class="header">isElement</b><code>_.isElement(object)</code>
  739. <br />
  740. Returns <i>true</i> if <b>object</b> is a DOM element.
  741. </p>
  742. <pre>
  743. _.isElement(jQuery('body')[0]);
  744. =&gt; true
  745. </pre>
  746. <p id="isArray">
  747. <b class="header">isArray</b><code>_.isArray(object)</code>
  748. <br />
  749. Returns <i>true</i> if <b>object</b> is an Array.
  750. </p>
  751. <pre>
  752. (function(){ return _.isArray(arguments); })();
  753. =&gt; false
  754. _.isArray([1,2,3]);
  755. =&gt; true
  756. </pre>
  757. <p id="isArguments">
  758. <b class="header">isArguments</b><code>_.isArguments(object)</code>
  759. <br />
  760. Returns <i>true</i> if <b>object</b> is an Arguments object.
  761. </p>
  762. <pre>
  763. (function(){ return _.isArguments(arguments); })(1, 2, 3);
  764. =&gt; true
  765. _.isArguments([1,2,3]);
  766. =&gt; false
  767. </pre>
  768. <p id="isFunction">
  769. <b class="header">isFunction</b><code>_.isFunction(object)</code>
  770. <br />
  771. Returns <i>true</i> if <b>object</b> is a Function.
  772. </p>
  773. <pre>
  774. _.isFunction(alert);
  775. =&gt; true
  776. </pre>
  777. <p id="isString">
  778. <b class="header">isString</b><code>_.isString(object)</code>
  779. <br />
  780. Returns <i>true</i> if <b>object</b> is a String.
  781. </p>
  782. <pre>
  783. _.isFunction("moe");
  784. =&gt; true
  785. </pre>
  786. <p id="isNumber">
  787. <b class="header">isNumber</b><code>_.isNumber(object)</code>
  788. <br />
  789. Returns <i>true</i> if <b>object</b> is a Number.
  790. </p>
  791. <pre>
  792. _.isNumber(8.4 * 5);
  793. =&gt; true
  794. </pre>
  795. <p id="isDate">
  796. <b class="header">isDate</b><code>_.isDate(object)</code>
  797. <br />
  798. Returns <i>true</i> if <b>object</b> is a Date.
  799. </p>
  800. <pre>
  801. _.isDate(new Date());
  802. =&gt; true
  803. </pre>
  804. <p id="isRegExp">
  805. <b class="header">isRegExp</b><code>_.isRegExp(object)</code>
  806. <br />
  807. Returns <i>true</i> if <b>object</b> is a RegExp.
  808. </p>
  809. <pre>
  810. _.isRegExp(/moe/);
  811. =&gt; true
  812. </pre>
  813. <p id="isNaN">
  814. <b class="header">isNaN</b><code>_.isNaN(object)</code>
  815. <br />
  816. Returns <i>true</i> if <b>object</b> is <i>NaN</i>.<br /> Note: this is not
  817. the same as the native <b>isNaN</b> function, which will also return
  818. true if the variable is <i>undefined</i>.
  819. </p>
  820. <pre>
  821. _.isNaN(NaN);
  822. =&gt; true
  823. isNaN(undefined);
  824. =&gt; true
  825. _.isNaN(undefined);
  826. =&gt; false
  827. </pre>
  828. <p id="isNull">
  829. <b class="header">isNull</b><code>_.isNull(object)</code>
  830. <br />
  831. Returns <i>true</i> if the value of <b>object</b> is <i>null</i>.
  832. </p>
  833. <pre>
  834. _.isNull(null);
  835. =&gt; true
  836. _.isNull(undefined);
  837. =&gt; false
  838. </pre>
  839. <p id="isUndefined">
  840. <b class="header">isUndefined</b><code>_.isUndefined(variable)</code>
  841. <br />
  842. Returns <i>true</i> if <b>variable</b> is <i>undefined</i>.
  843. </p>
  844. <pre>
  845. _.isUndefined(window.missingVariable);
  846. =&gt; true
  847. </pre>
  848. <h2>Utility Functions</h2>
  849. <p id="noConflict">
  850. <b class="header">noConflict</b><code>_.noConflict()</code>
  851. <br />
  852. Give control of the "_" variable back to its previous owner. Returns
  853. a reference to the <b>Underscore</b> object.
  854. </p>
  855. <pre>
  856. var underscore = _.noConflict();</pre>
  857. <p id="identity">
  858. <b class="header">identity</b><code>_.identity(value)</code>
  859. <br />
  860. Returns the same value that is used as the argument. In math:
  861. <tt>f(x) = x</tt><br />
  862. This function looks useless, but is used throughout Underscore as
  863. a default iterator.
  864. </p>
  865. <pre>
  866. var moe = {name : 'moe'};
  867. moe === _.identity(moe);
  868. =&gt; true</pre>
  869. <p id="breakLoop">
  870. <b class="header">breakLoop</b><code>_.breakLoop()</code>
  871. <br />
  872. Breaks out of the current loop iteration. Similar to the <tt>break</tt>
  873. keyword in regular "for" loop, but works within an iterator function.
  874. Uses the native <tt>StopIteration</tt> object in JavaScript 1.7 compliant
  875. browsers.
  876. </p>
  877. <pre>
  878. var result = null;
  879. _.each([1, 2, 3], function(num) {
  880. if ((result = num) == 2) _.breakLoop();
  881. });
  882. result;
  883. =&gt; 2</pre>
  884. <p id="uniqueId">
  885. <b class="header">uniqueId</b><code>_.uniqueId([prefix])</code>
  886. <br />
  887. Generate a globally-unique id for client-side models or DOM elements
  888. that need one. If <b>prefix</b> is passed, the id will be appended to it.
  889. </p>
  890. <pre>
  891. _.uniqueId('contact_');
  892. =&gt; 'contact_104'</pre>
  893. <p id="template">
  894. <b class="header">template</b><code>_.template(templateString, [context])</code>
  895. <br />
  896. Compiles JavaScript templates into functions that can be evaluated
  897. for rendering. Useful for rendering complicated bits of HTML from JSON
  898. data sources. Template functions can both interpolate variables, using<br />
  899. <tt>&lt;%= &hellip; %&gt;</tt>, as well as execute arbitrary JavaScript code, with
  900. <tt>&lt;% &hellip; %&gt;</tt>. When you evaluate a template function, pass in a
  901. <b>context</b> object that has properties corresponding to the template's free
  902. variables. If you're writing a one-off, you can pass the <b>context</b>
  903. object as the second parameter to <b>template</b> in order to render
  904. immediately instead of returning a template function.
  905. </p>
  906. <pre>
  907. var compiled = _.template("hello: &lt;%= name %&gt;");
  908. compiled({name : 'moe'});
  909. =&gt; "hello: moe"
  910. var list = "&lt;% _.each(people, function(name) { %&gt; &lt;li&gt;&lt;%= name %&gt;&lt;/li&gt; &lt;% }); %&gt;";
  911. _.template(list, {people : ['moe', 'curly', 'larry']});
  912. =&gt; "&lt;li&gt;moe&lt;/li&gt;&lt;li&gt;curly&lt;/li&gt;&lt;li&gt;larry&lt;/li&gt;"</pre>
  913. <p>
  914. If ERB-style delimiters aren't your cup of tea, you can change Underscore's
  915. template settings to use different symbols to set off interpolated code.
  916. Define <b>start</b> and <b>end</b> tokens, and an <b>interpolate</b> regex
  917. to match expressions that should be evaluated and inserted. For example,
  918. to perform
  919. <a href="http://github.com/janl/mustache.js#readme">Mustache.js</a>
  920. style templating:
  921. </p>
  922. <pre>
  923. _.templateSettings = {
  924. start : '{{',
  925. end : '}}',
  926. interpolate : /\{\{(.+?)\}\}/g
  927. };
  928. var template = _.template("Hello {{ name }}!");
  929. template({name : "Mustache"});
  930. =&gt; "Hello Mustache!"</pre>
  931. <h2>Chaining</h2>
  932. <p id="chain">
  933. <b class="header">chain</b><code>_(obj).chain()</code>
  934. <br />
  935. Returns a wrapped object. Calling methods on this object will continue
  936. to return wrapped objects until <tt>value</tt> is used. (
  937. <a href="#styles">A more realistic example.</a>)
  938. </p>
  939. <pre>
  940. var stooges = [{name : 'curly', age : 25}, {name : 'moe', age : 21}, {name : 'larry', age : 23}];
  941. var youngest = _(stooges).chain()
  942. .sortBy(function(stooge){ return stooge.age; })
  943. .map(function(stooge){ return stooge.name + ' is ' + stooge.age; })
  944. .first()
  945. .value();
  946. =&gt; "moe is 21"
  947. </pre>
  948. <p id="value">
  949. <b class="header">value</b><code>_(obj).value()</code>
  950. <br />
  951. Extracts the value of a wrapped object.
  952. </p>
  953. <pre>
  954. _([1, 2, 3]).value();
  955. =&gt; [1, 2, 3]
  956. </pre>
  957. <h2 id="duck_typing">Duck Typing</h2>
  958. <p>
  959. The <b>isType</b> (<tt>isArray</tt>, <tt>isFunction</tt>, <tt>isString</tt> ...) family of type-checking
  960. functions use property detection to do their work, which, although
  961. orders of magnitude faster than the alternative, isn't entirely safe when dealing
  962. with objects that are used as hashes, where arbitrary strings are being
  963. set for the keys. It's entirely possible for an object to masquerade as
  964. another type, if you're setting properties with names like "concat" and
  965. "charCodeAt". So be aware.
  966. </p>
  967. <h2>Links &amp; Suggested Reading</h2>
  968. <p>
  969. <a href="http://mirven.github.com/underscore.lua/">Underscore.lua</a>,
  970. a Lua port of the functions that are applicable in both languages.
  971. Includes OOP-wrapping and chaining.
  972. The <a href="http://github.com/mirven/underscore.lua">source</a> is
  973. available on GitHub.
  974. </p>
  975. <p>
  976. Ruby's <a href="http://ruby-doc.org/core/classes/Enumerable.html">Enumerable</a> module.
  977. </p>
  978. <p>
  979. <a href="http://www.prototypejs.org/">Prototype.js</a>, which provides
  980. JavaScript with collection functions in the manner closest to Ruby's Enumerable.
  981. </p>
  982. <p>
  983. Oliver Steele's
  984. <a href="http://osteele.com/sources/javascript/functional/">Functional JavaScript</a>,
  985. which includes comprehensive higher-order function support as well as string lambdas.
  986. </p>
  987. <p>
  988. Python's <a href="http://docs.python.org/library/itertools.html">itertools</a>.
  989. </p>
  990. <h2>Change Log</h2>
  991. <p>
  992. <b class="header">0.5.8</b><br />
  993. Fixed Underscore's collection functions to work on
  994. <a href="https://developer.mozilla.org/En/DOM/NodeList">NodeLists</a> and
  995. <a href="https://developer.mozilla.org/En/DOM/HTMLCollection">HTMLCollections</a>
  996. once more, thanks to
  997. <a href="http://github.com/jmtulloss">Justin Tulloss</a>.
  998. </p>
  999. <p>
  1000. <b class="header">0.5.7</b><br />
  1001. A safer implementation of <tt>_.isArguments</tt>, and a
  1002. faster <tt>_.isNumber</tt>,<br />thanks to
  1003. <a href="http://jedschmidt.com/">Jed Schmidt</a>.
  1004. </p>
  1005. <p>
  1006. <b class="header">0.5.6</b><br />
  1007. Customizable delimiters for <tt>_.template</tt>, contributed by
  1008. <a href="http://github.com/iamnoah">Noah Sloan</a>.
  1009. </p>
  1010. <p>
  1011. <b class="header">0.5.5</b><br />
  1012. Fix for a bug in MobileSafari's OOP-wrapper, with the arguments object.
  1013. </p>
  1014. <p>
  1015. <b class="header">0.5.4</b><br />
  1016. Fix for multiple single quotes within a template string for
  1017. <tt>_.template</tt>. See:
  1018. <a href="http://www.west-wind.com/Weblog/posts/509108.aspx">Rick Strahl's blog post</a>.
  1019. </p>
  1020. <p>
  1021. <b class="header">0.5.2</b><br />
  1022. New implementations of <tt>isArray</tt>, <tt>isDate</tt>, <tt>isFunction</tt>,
  1023. <tt>isNumber</tt>, <tt>isRegExp</tt>, and <tt>isString</tt>, thanks to
  1024. a suggestion from
  1025. <a href="http://www.broofa.com/">Robert Kieffer</a>.
  1026. Instead of doing <tt>Object#toString</tt>
  1027. comparisons, they now check for expected properties, which is less safe,
  1028. but more than an order of magnitude faster. Most other Underscore
  1029. functions saw minor speed improvements as a result.
  1030. <a href="http://dolzhenko.org/">Evgeniy Dolzhenko</a>
  1031. contributed <tt>_.tap</tt>,
  1032. <a href="http://ruby-doc.org/core-1.9/classes/Object.html#M000191">similar to Ruby 1.9's</a>,
  1033. which is handy for injecting side effects (like logging) into chained calls.
  1034. </p>
  1035. <p>
  1036. <b class="header">0.5.1</b><br />
  1037. Added an <tt>_.isArguments</tt> function. Lots of little safety checks
  1038. and optimizations contributed by
  1039. <a href="http://github.com/iamnoah/">Noah Sloan</a> and Andri Möll.
  1040. </p>
  1041. <p>
  1042. <b class="header">0.5.0</b><br />
  1043. <b>[API Changes]</b> <tt>_.bindAll</tt> now takes the context object as
  1044. its first parameter. If no method names are passed, all of the context
  1045. object's methods are bound to it, enabling chaining and easier binding.
  1046. <tt>_.functions</tt> now takes a single argument and returns the names
  1047. of its Function properties. Calling <tt>_.functions(_)</tt> will get you
  1048. the previous behavior.
  1049. Added <tt>_.isRegExp</tt> so that <tt>isEqual</tt> can now test for RegExp equality.
  1050. All of the "is" functions have been shrunk down into a single definition.
  1051. <a href="http://github.com/grayrest/">Karl Guertin</a> contributed patches.
  1052. </p>
  1053. <p>
  1054. <b class="header">0.4.7</b><br />
  1055. Added <tt>isDate</tt>, <tt>isNaN</tt>, and <tt>isNull</tt>, for completeness.
  1056. Optimizations for <tt>isEqual</tt> when checking equality between Arrays
  1057. or Dates. <tt>_.keys</tt> is now <small><i><b>25%&ndash;2X</b></i></small> faster (depending on your
  1058. browser) which speeds up the functions that rely on it, such as <tt>_.each</tt>.
  1059. </p>
  1060. <p>
  1061. <b class="header">0.4.6</b><br />
  1062. Added the <tt>range</tt> function, a port of the
  1063. <a href="http://docs.python.org/library/functions.html#range">Python
  1064. function of the same name</a>, for generating flexibly-numbered lists
  1065. of integers. Original patch contributed by
  1066. <a href="http://github.com/kylichuku">Kirill Ishanov</a>.
  1067. </p>
  1068. <p>
  1069. <b class="header">0.4.5</b><br />
  1070. Added <tt>rest</tt> for Arrays and arguments objects, and aliased
  1071. <tt>first</tt> as <tt>head</tt>, and <tt>rest</tt> as <tt>tail</tt>,
  1072. thanks to <a href="http://github.com/lukesutton/">Luke Sutton</a>'s patches.
  1073. Added tests ensuring that all Underscore Array functions also work on
  1074. <i>arguments</i> objects.
  1075. </p>
  1076. <p>
  1077. <b class="header">0.4.4</b><br />
  1078. Added <tt>isString</tt>, and <tt>isNumber</tt>, for consistency. Fixed
  1079. <tt>_.isEqual(NaN, NaN)</tt> to return <i>true</i> (which is debatable).
  1080. </p>
  1081. <p>
  1082. <b class="header">0.4.3</b><br />
  1083. Started using the native <tt>StopIteration</tt> object in browsers that support it.
  1084. Fixed Underscore setup for CommonJS environments.
  1085. </p>
  1086. <p>
  1087. <b class="header">0.4.2</b><br />
  1088. Renamed the unwrapping function to <tt>value</tt>, for clarity.
  1089. </p>
  1090. <p>
  1091. <b class="header">0.4.1</b><br />
  1092. Chained Underscore objects now support the Array prototype methods, so
  1093. that you can perform the full range of operations on a wrapped array
  1094. without having to break your chain. Added a <tt>breakLoop</tt> method
  1095. to <b>break</b> in the middle of any Underscore iteration. Added an
  1096. <tt>isEmpty</tt> function that works on arrays and objects.
  1097. </p>
  1098. <p>
  1099. <b class="header">0.4.0</b><br />
  1100. All Underscore functions can now be called in an object-oriented style,
  1101. like so: <tt>_([1, 2, 3]).map(...);</tt>. Original patch provided by
  1102. <a href="http://macournoyer.com/">Marc-André Cournoyer</a>.
  1103. Wrapped objects can be chained through multiple
  1104. method invocations. A <a href="#functions"><tt>functions</tt></a> method
  1105. was added, providing a sorted list of all the functions in Underscore.
  1106. </p>
  1107. <p>
  1108. <b class="header">0.3.3</b><br />
  1109. Added the JavaScript 1.8 function <tt>reduceRight</tt>. Aliased it
  1110. as <tt>foldr</tt>, and aliased <tt>reduce</tt> as <tt>foldl</tt>.
  1111. </p>
  1112. <p>
  1113. <b class="header">0.3.2</b><br />
  1114. Now runs on stock <a href="http://www.mozilla.org/rhino/">Rhino</a>
  1115. interpreters with: <tt>load("underscore.js")</tt>.
  1116. Added <a href="#identity"><tt>identity</tt></a> as a utility function.
  1117. </p>
  1118. <p>
  1119. <b class="header">0.3.1</b><br />
  1120. All iterators are now passed in the original collection as their third
  1121. argument, the same as JavaScript 1.6's <b>forEach</b>. Iterating over
  1122. objects is now called with <tt>(value, key, collection)</tt>, for details
  1123. see <a href="#each"><tt>_.each</tt></a>.
  1124. </p>
  1125. <p>
  1126. <b class="header">0.3.0</b><br />
  1127. Added <a href="http://github.com/dmitryBaranovskiy">Dmitry Baranovskiy</a>'s
  1128. comprehensive optimizations, merged in
  1129. <a href="http://github.com/kriskowal/">Kris Kowal</a>'s patches to make Underscore
  1130. <a href="http://wiki.commonjs.org/wiki/CommonJS">CommonJS</a> and
  1131. <a href="http://narwhaljs.org/">Narwhal</a> compliant.
  1132. </p>
  1133. <p>
  1134. <b class="header">0.2.0</b><br />
  1135. Added <tt>compose</tt> and <tt>lastIndexOf</tt>, renamed <tt>inject</tt> to
  1136. <tt>reduce</tt>, added aliases for <tt>inject</tt>, <tt>filter</tt>,
  1137. <tt>every</tt>, <tt>some</tt>, and <tt>forEach</tt>.
  1138. </p>
  1139. <p>
  1140. <b class="header">0.1.1</b><br />
  1141. Added <tt>noConflict</tt>, so that the "Underscore" object can be assigned to
  1142. other variables.
  1143. </p>
  1144. <p>
  1145. <b class="header">0.1.0</b><br />
  1146. Initial release of Underscore.js.
  1147. </p>
  1148. <p>
  1149. <a href="http://documentcloud.org/" title="A DocumentCloud Project" style="background:none;">
  1150. <img src="http://jashkenas.s3.amazonaws.com/images/a_documentcloud_project.png" alt="A DocumentCloud Project" />
  1151. </a>
  1152. </p>
  1153. </div>
  1154. </div>
  1155. </body>
  1156. </html>