PageRenderTime 65ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/node_modules/nano/node_modules/underscore/index.html

http://github.com/gradus/cupcake-demo
HTML | 1777 lines | 1601 code | 175 blank | 1 comment | 0 complexity | 5dc80fb28d11932617fc2f653ff6fc12 MD5 | raw file
Possible License(s): BSD-3-Clause, MIT, Apache-2.0
  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. ul {
  53. list-style-type: circle;
  54. padding: 0 0 0 20px;
  55. }
  56. li {
  57. width: 500px;
  58. margin-bottom: 10px;
  59. }
  60. code, pre, tt {
  61. font-family: Monaco, Consolas, "Lucida Console", monospace;
  62. font-size: 12px;
  63. line-height: 18px;
  64. color: #555529;
  65. }
  66. code {
  67. margin-left: 20px;
  68. }
  69. pre {
  70. font-size: 12px;
  71. padding: 2px 0 2px 12px;
  72. border-left: 6px solid #aaaa99;
  73. margin: 0px 0 30px;
  74. }
  75. </style>
  76. </head>
  77. <body>
  78. <div class="container">
  79. <h1>Underscore.js</h1>
  80. <p>
  81. <a href="http://github.com/documentcloud/underscore/">Underscore</a> is a
  82. utility-belt library for JavaScript that provides a lot of the
  83. functional programming support that you would expect in
  84. <a href="http://prototypejs.org/api">Prototype.js</a>
  85. (or <a href="http://www.ruby-doc.org/core/classes/Enumerable.html">Ruby</a>),
  86. but without extending any of the built-in JavaScript objects. It's the
  87. tie to go along with <a href="http://docs.jquery.com">jQuery</a>'s tux.
  88. </p>
  89. <p>
  90. Underscore provides 60-odd functions that support both the usual
  91. functional suspects: <b>map</b>, <b>select</b>, <b>invoke</b> &mdash;
  92. as well as more specialized helpers: function binding, javascript
  93. templating, deep equality testing, and so on. It delegates to built-in
  94. functions, if present, so modern browsers will use the
  95. native implementations of <b>forEach</b>, <b>map</b>, <b>reduce</b>,
  96. <b>filter</b>, <b>every</b>, <b>some</b> and <b>indexOf</b>.
  97. </p>
  98. <p>
  99. A complete <a href="test/test.html">Test &amp; Benchmark Suite</a>
  100. is included for your perusal.
  101. </p>
  102. <p>
  103. You may also read through the <a href="docs/underscore.html">annotated source code</a>.
  104. </p>
  105. <p>
  106. The project is
  107. <a href="http://github.com/documentcloud/underscore/">hosted on GitHub</a>.
  108. You can report bugs and discuss features on the
  109. <a href="http://github.com/documentcloud/underscore/issues">issues page</a>,
  110. on Freenode in the <tt>#documentcloud</tt> channel,
  111. or send tweets to <a href="http://twitter.com/documentcloud">@documentcloud</a>.
  112. </p>
  113. <p>
  114. <i>Underscore is an open-source component of <a href="http://documentcloud.org/">DocumentCloud</a>.</i>
  115. </p>
  116. <h2>Downloads <i style="padding-left: 12px; font-size:12px;">(Right-click, and use "Save As")</i></h2>
  117. <table>
  118. <tr>
  119. <td><a href="underscore.js">Development Version (1.2.3)</a></td>
  120. <td><i>34kb, Uncompressed with Comments</i></td>
  121. </tr>
  122. <tr>
  123. <td><a href="underscore-min.js">Production Version (1.2.3)</a></td>
  124. <td><i>&lt; 4kb, Minified and Gzipped</i></td>
  125. </tr>
  126. </table>
  127. <h2>Table of Contents</h2>
  128. <a href="#styles">Object-Oriented and Functional Styles</a>
  129. <p>
  130. <b>Collections</b>
  131. <br />
  132. <span class="methods"><a href="#each">each</a>, <a href="#map">map</a>,
  133. <a href="#reduce">reduce</a>, <a href="#reduceRight">reduceRight</a>,
  134. <a href="#find">find</a>, <a href="#filter">filter</a>,
  135. <a href="#reject">reject</a>, <a href="#all">all</a>,
  136. <a href="#any">any</a>, <a href="#include">include</a>,
  137. <a href="#invoke">invoke</a>, <a href="#pluck">pluck</a>,
  138. <a href="#max">max</a>, <a href="#min">min</a>,
  139. <a href="#sortBy">sortBy</a>, <a href="#groupBy">groupBy</a>,
  140. <a href="#sortedIndex">sortedIndex</a>, <a href="#shuffle">shuffle</a>,
  141. <a href="#toArray">toArray</a>, <a href="#size">size</a></span>
  142. </p>
  143. <p>
  144. <b>Arrays</b>
  145. <br />
  146. <span class="methods"><a href="#first">first</a>, <a href="#initial">initial</a>, <a href="#last">last</a>, <a href="#rest">rest</a>,
  147. <a href="#compact">compact</a>, <a href="#flatten">flatten</a>, <a href="#without">without</a>,
  148. <a href="#union">union</a>, <a href="#intersection">intersection</a>, <a href="#difference">difference</a>,
  149. <a href="#uniq">uniq</a>, <a href="#zip">zip</a>, <a href="#indexOf">indexOf</a>,
  150. <a href="#lastIndexOf">lastIndexOf</a>, <a href="#range">range</a></span>
  151. </p>
  152. <p>
  153. <b>Functions</b>
  154. <br />
  155. <span class="methods"><a href="#bind">bind</a>, <a href="#bindAll">bindAll</a>,
  156. <a href="#memoize">memoize</a>, <a href="#delay">delay</a>, <a href="#defer">defer</a>,
  157. <a href="#throttle">throttle</a>, <a href="#debounce">debounce</a>,
  158. <a href="#once">once</a>, <a href="#after">after</a>, <a href="#wrap">wrap</a>, <a href="#compose">compose</a></span>
  159. </p>
  160. <p>
  161. <b>Objects</b>
  162. <br />
  163. <span class="methods"><a href="#keys">keys</a>, <a href="#values">values</a>,
  164. <a href="#functions">functions</a>, <a href="#extend">extend</a>, <a href="#defaults">defaults</a>, <a href="#clone">clone</a>, <a href="#tap">tap</a>,
  165. <a href="#isEqual">isEqual</a>, <a href="#isEmpty">isEmpty</a>, <a href="#isElement">isElement</a>,
  166. <a href="#isArray">isArray</a>, <a href="#isArguments">isArguments</a>, <a href="#isFunction">isFunction</a>, <a href="#isString">isString</a>,
  167. <a href="#isNumber">isNumber</a>, <a href="#isBoolean">isBoolean</a>, <a href="#isDate">isDate</a>, <a href="#isRegExp">isRegExp</a>,
  168. <a href="#isNaN">isNaN</a>, <a href="#isNull">isNull</a>,
  169. <a href="#isUndefined">isUndefined</a>
  170. </span>
  171. </p>
  172. <p>
  173. <b>Utility</b>
  174. <br />
  175. <span class="methods"><a href="#noConflict">noConflict</a>,
  176. <a href="#identity">identity</a>, <a href="#times">times</a>,
  177. <a href="#mixin">mixin</a>, <a href="#uniqueId">uniqueId</a>,
  178. <a href="#escape">escape</a>, <a href="#template">template</a></span>
  179. </p>
  180. <p>
  181. <b>Chaining</b>
  182. <br />
  183. <span class="methods"><a href="#chain">chain</a>, <a href="#value">value</a>
  184. </p>
  185. <div id="documentation">
  186. <h2 id="styles">Object-Oriented and Functional Styles</h2>
  187. <p>
  188. You can use Underscore in either an object-oriented or a functional style,
  189. depending on your preference. The following two lines of code are
  190. identical ways to double a list of numbers.
  191. </p>
  192. <pre>
  193. _.map([1, 2, 3], function(n){ return n * 2; });
  194. _([1, 2, 3]).map(function(n){ return n * 2; });</pre>
  195. <p>
  196. Using the object-oriented style allows you to chain together methods. Calling
  197. <tt>chain</tt> on a wrapped object will cause all future method calls to
  198. return wrapped objects as well. When you've finished the computation,
  199. use <tt>value</tt> to retrieve the final value. Here's an example of chaining
  200. together a <b>map/flatten/reduce</b>, in order to get the word count of
  201. every word in a song.
  202. </p>
  203. <pre>
  204. var lyrics = [
  205. {line : 1, words : "I'm a lumberjack and I'm okay"},
  206. {line : 2, words : "I sleep all night and I work all day"},
  207. {line : 3, words : "He's a lumberjack and he's okay"},
  208. {line : 4, words : "He sleeps all night and he works all day"}
  209. ];
  210. _(lyrics).chain()
  211. .map(function(line) { return line.words.split(' '); })
  212. .flatten()
  213. .reduce(function(counts, word) {
  214. counts[word] = (counts[word] || 0) + 1;
  215. return counts;
  216. }, {}).value();
  217. =&gt; {lumberjack : 2, all : 4, night : 2 ... }</pre>
  218. <p>
  219. In addition, the
  220. <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/prototype">Array prototype's methods</a>
  221. are proxied through the chained Underscore object, so you can slip a
  222. <tt>reverse</tt> or a <tt>push</tt> into your chain, and continue to
  223. modify the array.
  224. </p>
  225. <h2>Collection Functions (Arrays or Objects)</h2>
  226. <p id="each">
  227. <b class="header">each</b><code>_.each(list, iterator, [context])</code>
  228. <span class="alias">Alias: <b>forEach</b></span>
  229. <br />
  230. Iterates over a <b>list</b> of elements, yielding each in turn to an <b>iterator</b>
  231. function. The <b>iterator</b> is bound to the <b>context</b> object, if one is
  232. passed. Each invocation of <b>iterator</b> is called with three arguments:
  233. <tt>(element, index, list)</tt>. If <b>list</b> is a JavaScript object, <b>iterator</b>'s
  234. arguments will be <tt>(value, key, list)</tt>. Delegates to the native
  235. <b>forEach</b> function if it exists.
  236. </p>
  237. <pre>
  238. _.each([1, 2, 3], function(num){ alert(num); });
  239. =&gt; alerts each number in turn...
  240. _.each({one : 1, two : 2, three : 3}, function(num, key){ alert(num); });
  241. =&gt; alerts each number in turn...</pre>
  242. <p id="map">
  243. <b class="header">map</b><code>_.map(list, iterator, [context])</code>
  244. <br />
  245. Produces a new array of values by mapping each value in <b>list</b>
  246. through a transformation function (<b>iterator</b>). If the native <b>map</b> method
  247. exists, it will be used instead. If <b>list</b> is a JavaScript object,
  248. <b>iterator</b>'s arguments will be <tt>(value, key, list)</tt>.
  249. </p>
  250. <pre>
  251. _.map([1, 2, 3], function(num){ return num * 3; });
  252. =&gt; [3, 6, 9]
  253. _.map({one : 1, two : 2, three : 3}, function(num, key){ return num * 3; });
  254. =&gt; [3, 6, 9]</pre>
  255. <p id="reduce">
  256. <b class="header">reduce</b><code>_.reduce(list, iterator, memo, [context])</code>
  257. <span class="alias">Aliases: <b>inject, foldl</b></span>
  258. <br />
  259. Also known as <b>inject</b> and <b>foldl</b>, <b>reduce</b> boils down a
  260. <b>list</b> of values into a single value. <b>Memo</b> is the initial state
  261. of the reduction, and each successive step of it should be returned by
  262. <b>iterator</b>.
  263. </p>
  264. <pre>
  265. var sum = _.reduce([1, 2, 3], function(memo, num){ return memo + num; }, 0);
  266. =&gt; 6
  267. </pre>
  268. <p id="reduceRight">
  269. <b class="header">reduceRight</b><code>_.reduceRight(list, iterator, memo, [context])</code>
  270. <span class="alias">Alias: <b>foldr</b></span>
  271. <br />
  272. The right-associative version of <b>reduce</b>. Delegates to the
  273. JavaScript 1.8 version of <b>reduceRight</b>, if it exists. <b>Foldr</b>
  274. is not as useful in JavaScript as it would be in a language with lazy
  275. evaluation.
  276. </p>
  277. <pre>
  278. var list = [[0, 1], [2, 3], [4, 5]];
  279. var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []);
  280. =&gt; [4, 5, 2, 3, 0, 1]
  281. </pre>
  282. <p id="find">
  283. <b class="header">find</b><code>_.find(list, iterator, [context])</code>
  284. <span class="alias">Alias: <b>detect</b></span>
  285. <br />
  286. Looks through each value in the <b>list</b>, returning the first one that
  287. passes a truth test (<b>iterator</b>). The function returns as
  288. soon as it finds an acceptable element, and doesn't traverse the
  289. entire list.
  290. </p>
  291. <pre>
  292. var even = _.find([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
  293. =&gt; 2
  294. </pre>
  295. <p id="filter">
  296. <b class="header">filter</b><code>_.filter(list, iterator, [context])</code>
  297. <span class="alias">Alias: <b>select</b></span>
  298. <br />
  299. Looks through each value in the <b>list</b>, returning an array of all
  300. the values that pass a truth test (<b>iterator</b>). Delegates to the
  301. native <b>filter</b> method, if it exists.
  302. </p>
  303. <pre>
  304. var evens = _.filter([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
  305. =&gt; [2, 4, 6]
  306. </pre>
  307. <p id="reject">
  308. <b class="header">reject</b><code>_.reject(list, iterator, [context])</code>
  309. <br />
  310. Returns the values in <b>list</b> without the elements that the truth
  311. test (<b>iterator</b>) passes. The opposite of <b>filter</b>.
  312. </p>
  313. <pre>
  314. var odds = _.reject([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
  315. =&gt; [1, 3, 5]
  316. </pre>
  317. <p id="all">
  318. <b class="header">all</b><code>_.all(list, iterator, [context])</code>
  319. <span class="alias">Alias: <b>every</b></span>
  320. <br />
  321. Returns <i>true</i> if all of the values in the <b>list</b> pass the <b>iterator</b>
  322. truth test. Delegates to the native method <b>every</b>, if present.
  323. </p>
  324. <pre>
  325. _.all([true, 1, null, 'yes'], _.identity);
  326. =&gt; false
  327. </pre>
  328. <p id="any">
  329. <b class="header">any</b><code>_.any(list, [iterator], [context])</code>
  330. <span class="alias">Alias: <b>some</b></span>
  331. <br />
  332. Returns <i>true</i> if any of the values in the <b>list</b> pass the
  333. <b>iterator</b> truth test. Short-circuits and stops traversing the list
  334. if a true element is found. Delegates to the native method <b>some</b>,
  335. if present.
  336. </p>
  337. <pre>
  338. _.any([null, 0, 'yes', false]);
  339. =&gt; true
  340. </pre>
  341. <p id="include">
  342. <b class="header">include</b><code>_.include(list, value)</code>
  343. <span class="alias">Alias: <b>contains</b></span>
  344. <br />
  345. Returns <i>true</i> if the <b>value</b> is present in the <b>list</b>, using
  346. <i>===</i> to test equality. Uses <b>indexOf</b> internally, if <b>list</b>
  347. is an Array.
  348. </p>
  349. <pre>
  350. _.include([1, 2, 3], 3);
  351. =&gt; true
  352. </pre>
  353. <p id="invoke">
  354. <b class="header">invoke</b><code>_.invoke(list, methodName, [*arguments])</code>
  355. <br />
  356. Calls the method named by <b>methodName</b> on each value in the <b>list</b>.
  357. Any extra arguments passed to <b>invoke</b> will be forwarded on to the
  358. method invocation.
  359. </p>
  360. <pre>
  361. _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
  362. =&gt; [[1, 5, 7], [1, 2, 3]]
  363. </pre>
  364. <p id="pluck">
  365. <b class="header">pluck</b><code>_.pluck(list, propertyName)</code>
  366. <br />
  367. A convenient version of what is perhaps the most common use-case for
  368. <b>map</b>: extracting a list of property values.
  369. </p>
  370. <pre>
  371. var stooges = [{name : 'moe', age : 40}, {name : 'larry', age : 50}, {name : 'curly', age : 60}];
  372. _.pluck(stooges, 'name');
  373. =&gt; ["moe", "larry", "curly"]
  374. </pre>
  375. <p id="max">
  376. <b class="header">max</b><code>_.max(list, [iterator], [context])</code>
  377. <br />
  378. Returns the maximum value in <b>list</b>. If <b>iterator</b> is passed,
  379. it will be used on each value to generate the criterion by which the
  380. value is ranked.
  381. </p>
  382. <pre>
  383. var stooges = [{name : 'moe', age : 40}, {name : 'larry', age : 50}, {name : 'curly', age : 60}];
  384. _.max(stooges, function(stooge){ return stooge.age; });
  385. =&gt; {name : 'curly', age : 60};
  386. </pre>
  387. <p id="min">
  388. <b class="header">min</b><code>_.min(list, [iterator], [context])</code>
  389. <br />
  390. Returns the minimum value in <b>list</b>. If <b>iterator</b> is passed,
  391. it will be used on each value to generate the criterion by which the
  392. value is ranked.
  393. </p>
  394. <pre>
  395. var numbers = [10, 5, 100, 2, 1000];
  396. _.min(numbers);
  397. =&gt; 2
  398. </pre>
  399. <p id="sortBy">
  400. <b class="header">sortBy</b><code>_.sortBy(list, iterator, [context])</code>
  401. <br />
  402. Returns a sorted copy of <b>list</b>, ranked by the results of running
  403. each value through <b>iterator</b>.
  404. </p>
  405. <pre>
  406. _.sortBy([1, 2, 3, 4, 5, 6], function(num){ return Math.sin(num); });
  407. =&gt; [5, 4, 6, 3, 1, 2]
  408. </pre>
  409. <p id="groupBy">
  410. <b class="header">groupBy</b><code>_.groupBy(list, iterator)</code>
  411. <br />
  412. Splits a collection into sets, grouped by the result of running each
  413. value through <b>iterator</b>. If <b>iterator</b> is a string instead of
  414. a function, groups by the property named by <b>iterator</b> on each of
  415. the values.
  416. </p>
  417. <pre>
  418. _.groupBy([1.3, 2.1, 2.4], function(num){ return Math.floor(num); });
  419. =&gt; {1: [1.3], 2: [2.1, 2.4]}
  420. _.groupBy(['one', 'two', 'three'], 'length');
  421. =&gt; {3: ["one", "two"], 5: ["three"]}
  422. </pre>
  423. <p id="sortedIndex">
  424. <b class="header">sortedIndex</b><code>_.sortedIndex(list, value, [iterator])</code>
  425. <br />
  426. Uses a binary search to determine the index at which the <b>value</b>
  427. <i>should</i> be inserted into the <b>list</b> in order to maintain the <b>list</b>'s
  428. sorted order. If an <b>iterator</b> is passed, it will be used to compute
  429. the sort ranking of each value.
  430. </p>
  431. <pre>
  432. _.sortedIndex([10, 20, 30, 40, 50], 35);
  433. =&gt; 3
  434. </pre>
  435. <p id="shuffle">
  436. <b class="header">shuffle</b><code>_.shuffle(list)</code>
  437. <br />
  438. Returns a shuffled copy of the <b>list</b>, using a version of the
  439. <a href="http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle">Fisher-Yates shuffle</a>.
  440. </p>
  441. <pre>
  442. _.shuffle([1, 2, 3, 4, 5, 6]);
  443. =&gt; [4, 1, 6, 3, 5, 2]
  444. </pre>
  445. <p id="toArray">
  446. <b class="header">toArray</b><code>_.toArray(list)</code>
  447. <br />
  448. Converts the <b>list</b> (anything that can be iterated over), into a
  449. real Array. Useful for transmuting the <b>arguments</b> object.
  450. </p>
  451. <pre>
  452. (function(){ return _.toArray(arguments).slice(0); })(1, 2, 3);
  453. =&gt; [1, 2, 3]
  454. </pre>
  455. <p id="size">
  456. <b class="header">size</b><code>_.size(list)</code>
  457. <br />
  458. Return the number of values in the <b>list</b>.
  459. </p>
  460. <pre>
  461. _.size({one : 1, two : 2, three : 3});
  462. =&gt; 3
  463. </pre>
  464. <h2>Array Functions</h2>
  465. <p>
  466. <i>Note: All array functions will also work on the <b>arguments</b> object.</i>
  467. </p>
  468. <p id="first">
  469. <b class="header">first</b><code>_.first(array, [n])</code>
  470. <span class="alias">Alias: <b>head</b></span>
  471. <br />
  472. Returns the first element of an <b>array</b>. Passing <b>n</b> will
  473. return the first <b>n</b> elements of the array.
  474. </p>
  475. <pre>
  476. _.first([5, 4, 3, 2, 1]);
  477. =&gt; 5
  478. </pre>
  479. <p id="initial">
  480. <b class="header">initial</b><code>_.initial(array, [n])</code>
  481. <br />
  482. Returns everything but the last entry of the array. Especially useful on
  483. the arguments object. Pass <b>n</b> to exclude the last <b>n</b> elements
  484. from the result.
  485. </p>
  486. <pre>
  487. _.initial([5, 4, 3, 2, 1]);
  488. =&gt; [5, 4, 3, 2]
  489. </pre>
  490. <p id="last">
  491. <b class="header">last</b><code>_.last(array, [n])</code>
  492. <br />
  493. Returns the last element of an <b>array</b>. Passing <b>n</b> will return
  494. the last <b>n</b> elements of the array.
  495. </p>
  496. <pre>
  497. _.last([5, 4, 3, 2, 1]);
  498. =&gt; 1
  499. </pre>
  500. <p id="rest">
  501. <b class="header">rest</b><code>_.rest(array, [index])</code>
  502. <span class="alias">Alias: <b>tail</b></span>
  503. <br />
  504. Returns the <b>rest</b> of the elements in an array. Pass an <b>index</b>
  505. to return the values of the array from that index onward.
  506. </p>
  507. <pre>
  508. _.rest([5, 4, 3, 2, 1]);
  509. =&gt; [4, 3, 2, 1]
  510. </pre>
  511. <p id="compact">
  512. <b class="header">compact</b><code>_.compact(array)</code>
  513. <br />
  514. Returns a copy of the <b>array</b> with all falsy values removed.
  515. In JavaScript, <i>false</i>, <i>null</i>, <i>0</i>, <i>""</i>,
  516. <i>undefined</i> and <i>NaN</i> are all falsy.
  517. </p>
  518. <pre>
  519. _.compact([0, 1, false, 2, '', 3]);
  520. =&gt; [1, 2, 3]
  521. </pre>
  522. <p id="flatten">
  523. <b class="header">flatten</b><code>_.flatten(array)</code>
  524. <br />
  525. Flattens a nested <b>array</b> (the nesting can be to any depth).
  526. </p>
  527. <pre>
  528. _.flatten([1, [2], [3, [[[4]]]]]);
  529. =&gt; [1, 2, 3, 4];
  530. </pre>
  531. <p id="without">
  532. <b class="header">without</b><code>_.without(array, [*values])</code>
  533. <br />
  534. Returns a copy of the <b>array</b> with all instances of the <b>values</b>
  535. removed. <i>===</i> is used for the equality test.
  536. </p>
  537. <pre>
  538. _.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
  539. =&gt; [2, 3, 4]
  540. </pre>
  541. <p id="union">
  542. <b class="header">union</b><code>_.union(*arrays)</code>
  543. <br />
  544. Computes the union of the passed-in <b>arrays</b>: the list of unique items,
  545. in order, that are present in one or more of the <b>arrays</b>.
  546. </p>
  547. <pre>
  548. _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]);
  549. =&gt; [1, 2, 3, 101, 10]
  550. </pre>
  551. <p id="intersection">
  552. <b class="header">intersection</b><code>_.intersection(*arrays)</code>
  553. <br />
  554. Computes the list of values that are the intersection of all the <b>arrays</b>.
  555. Each value in the result is present in each of the <b>arrays</b>.
  556. </p>
  557. <pre>
  558. _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]);
  559. =&gt; [1, 2]
  560. </pre>
  561. <p id="difference">
  562. <b class="header">difference</b><code>_.difference(array, *others)</code>
  563. <br />
  564. Similar to <b>without</b>, but returns the values from <b>array</b> that
  565. are not present in the <b>other</b> arrays.
  566. </p>
  567. <pre>
  568. _.difference([1, 2, 3, 4, 5], [5, 2, 10]);
  569. =&gt; [1, 3, 4]
  570. </pre>
  571. <p id="uniq">
  572. <b class="header">uniq</b><code>_.uniq(array, [isSorted], [iterator])</code>
  573. <span class="alias">Alias: <b>unique</b></span>
  574. <br />
  575. Produces a duplicate-free version of the <b>array</b>, using <i>===</i> to test
  576. object equality. If you know in advance that the <b>array</b> is sorted,
  577. passing <i>true</i> for <b>isSorted</b> will run a much faster algorithm.
  578. If you want to compute unique items based on a transformation, pass an
  579. <b>iterator</b> function.
  580. </p>
  581. <pre>
  582. _.uniq([1, 2, 1, 3, 1, 4]);
  583. =&gt; [1, 2, 3, 4]
  584. </pre>
  585. <p id="zip">
  586. <b class="header">zip</b><code>_.zip(*arrays)</code>
  587. <br />
  588. Merges together the values of each of the <b>arrays</b> with the
  589. values at the corresponding position. Useful when you have separate
  590. data sources that are coordinated through matching array indexes.
  591. If you're working with a matrix of nested arrays, <b>zip.apply</b>
  592. can transpose the matrix in a similar fashion.
  593. </p>
  594. <pre>
  595. _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]);
  596. =&gt; [["moe", 30, true], ["larry", 40, false], ["curly", 50, false]]
  597. </pre>
  598. <p id="indexOf">
  599. <b class="header">indexOf</b><code>_.indexOf(array, value, [isSorted])</code>
  600. <br />
  601. Returns the index at which <b>value</b> can be found in the <b>array</b>,
  602. or <i>-1</i> if value is not present in the <b>array</b>. Uses the native
  603. <b>indexOf</b> function unless it's missing. If you're working with a
  604. large array, and you know that the array is already sorted, pass <tt>true</tt>
  605. for <b>isSorted</b> to use a faster binary search.
  606. </p>
  607. <pre>
  608. _.indexOf([1, 2, 3], 2);
  609. =&gt; 1
  610. </pre>
  611. <p id="lastIndexOf">
  612. <b class="header">lastIndexOf</b><code>_.lastIndexOf(array, value)</code>
  613. <br />
  614. Returns the index of the last occurrence of <b>value</b> in the <b>array</b>,
  615. or <i>-1</i> if value is not present. Uses the native <b>lastIndexOf</b>
  616. function if possible.
  617. </p>
  618. <pre>
  619. _.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
  620. =&gt; 4
  621. </pre>
  622. <p id="range">
  623. <b class="header">range</b><code>_.range([start], stop, [step])</code>
  624. <br />
  625. A function to create flexibly-numbered lists of integers, handy for
  626. <tt>each</tt> and <tt>map</tt> loops. <b>start</b>, if omitted, defaults
  627. to <i>0</i>; <b>step</b> defaults to <i>1</i>. Returns a list of integers
  628. from <b>start</b> to <b>stop</b>, incremented (or decremented) by <b>step</b>,
  629. exclusive.
  630. </p>
  631. <pre>
  632. _.range(10);
  633. =&gt; [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  634. _.range(1, 11);
  635. =&gt; [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  636. _.range(0, 30, 5);
  637. =&gt; [0, 5, 10, 15, 20, 25]
  638. _.range(0, -10, -1);
  639. =&gt; [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
  640. _.range(0);
  641. =&gt; []
  642. </pre>
  643. <h2>Function (uh, ahem) Functions</h2>
  644. <p id="bind">
  645. <b class="header">bind</b><code>_.bind(function, object, [*arguments])</code>
  646. <br />
  647. Bind a <b>function</b> to an <b>object</b>, meaning that whenever
  648. the function is called, the value of <i>this</i> will be the <b>object</b>.
  649. Optionally, bind <b>arguments</b> to the <b>function</b> to pre-fill them,
  650. also known as <b>currying</b>.
  651. </p>
  652. <pre>
  653. var func = function(greeting){ return greeting + ': ' + this.name };
  654. func = _.bind(func, {name : 'moe'}, 'hi');
  655. func();
  656. =&gt; 'hi: moe'
  657. </pre>
  658. <p id="bindAll">
  659. <b class="header">bindAll</b><code>_.bindAll(object, [*methodNames])</code>
  660. <br />
  661. Binds a number of methods on the <b>object</b>, specified by
  662. <b>methodNames</b>, to be run in the context of that object whenever they
  663. are invoked. Very handy for binding functions that are going to be used
  664. as event handlers, which would otherwise be invoked with a fairly useless
  665. <i>this</i>. If no <b>methodNames</b> are provided, all of the object's
  666. function properties will be bound to it.
  667. </p>
  668. <pre>
  669. var buttonView = {
  670. label : 'underscore',
  671. onClick : function(){ alert('clicked: ' + this.label); },
  672. onHover : function(){ console.log('hovering: ' + this.label); }
  673. };
  674. _.bindAll(buttonView);
  675. jQuery('#underscore_button').bind('click', buttonView.onClick);
  676. =&gt; When the button is clicked, this.label will have the correct value...
  677. </pre>
  678. <p id="memoize">
  679. <b class="header">memoize</b><code>_.memoize(function, [hashFunction])</code>
  680. <br />
  681. Memoizes a given <b>function</b> by caching the computed result. Useful
  682. for speeding up slow-running computations. If passed an optional
  683. <b>hashFunction</b>, it will be used to compute the hash key for storing
  684. the result, based on the arguments to the original function. The default
  685. <b>hashFunction</b> just uses the first argument to the memoized function
  686. as the key.
  687. </p>
  688. <pre>
  689. var fibonacci = _.memoize(function(n) {
  690. return n &lt; 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
  691. });
  692. </pre>
  693. <p id="delay">
  694. <b class="header">delay</b><code>_.delay(function, wait, [*arguments])</code>
  695. <br />
  696. Much like <b>setTimeout</b>, invokes <b>function</b> after <b>wait</b>
  697. milliseconds. If you pass the optional <b>arguments</b>, they will be
  698. forwarded on to the <b>function</b> when it is invoked.
  699. </p>
  700. <pre>
  701. var log = _.bind(console.log, console);
  702. _.delay(log, 1000, 'logged later');
  703. =&gt; 'logged later' // Appears after one second.
  704. </pre>
  705. <p id="defer">
  706. <b class="header">defer</b><code>_.defer(function)</code>
  707. <br />
  708. Defers invoking the <b>function</b> until the current call stack has cleared,
  709. similar to using <b>setTimeout</b> with a delay of 0. Useful for performing
  710. expensive computations or HTML rendering in chunks without blocking the UI thread
  711. from updating.
  712. </p>
  713. <pre>
  714. _.defer(function(){ alert('deferred'); });
  715. // Returns from the function before the alert runs.
  716. </pre>
  717. <p id="throttle">
  718. <b class="header">throttle</b><code>_.throttle(function, wait)</code>
  719. <br />
  720. Returns a throttled version of the function, that, when invoked repeatedly,
  721. will only actually call the wrapped function at most once per every <b>wait</b>
  722. milliseconds. Useful for rate-limiting events that occur faster than you
  723. can keep up with.
  724. </p>
  725. <pre>
  726. var throttled = _.throttle(updatePosition, 100);
  727. $(window).scroll(throttled);
  728. </pre>
  729. <p id="debounce">
  730. <b class="header">debounce</b><code>_.debounce(function, wait)</code>
  731. <br />
  732. Calling a debounced function will postpone its execution until after
  733. <b>wait</b> milliseconds have elapsed since the last time the function
  734. was invoked. Useful for implementing behavior that should only happen
  735. <i>after</i> the input has stopped arriving. For example: rendering a
  736. preview of a Markdown comment, recalculating a layout after the window
  737. has stopped being resized...
  738. </p>
  739. <pre>
  740. var lazyLayout = _.debounce(calculateLayout, 300);
  741. $(window).resize(lazyLayout);
  742. </pre>
  743. <p id="once">
  744. <b class="header">once</b><code>_.once(function)</code>
  745. <br />
  746. Creates a version of the function that can only be called one time.
  747. Repeated calls to the modified function will have no effect, returning
  748. the value from the original call. Useful for initialization functions,
  749. instead of having to set a boolean flag and then check it later.
  750. </p>
  751. <pre>
  752. var initialize = _.once(createApplication);
  753. initialize();
  754. initialize();
  755. // Application is only created once.
  756. </pre>
  757. <p id="after">
  758. <b class="header">after</b><code>_.after(count, function)</code>
  759. <br />
  760. Creates a version of the function that will only be run after first
  761. being called <b>count</b> times. Useful for grouping asynchronous responses,
  762. where you want to be sure that all the async calls have finished, before
  763. proceeding.
  764. </p>
  765. <pre>
  766. var renderNotes = _.after(notes.length, render);
  767. _.each(notes, function(note) {
  768. note.asyncSave({success: renderNotes});
  769. });
  770. // renderNotes is run once, after all notes have saved.
  771. </pre>
  772. <p id="wrap">
  773. <b class="header">wrap</b><code>_.wrap(function, wrapper)</code>
  774. <br />
  775. Wraps the first <b>function</b> inside of the <b>wrapper</b> function,
  776. passing it as the first argument. This allows the <b>wrapper</b> to
  777. execute code before and after the <b>function</b> runs, adjust the arguments,
  778. and execute it conditionally.
  779. </p>
  780. <pre>
  781. var hello = function(name) { return "hello: " + name; };
  782. hello = _.wrap(hello, function(func) {
  783. return "before, " + func("moe") + ", after";
  784. });
  785. hello();
  786. =&gt; 'before, hello: moe, after'
  787. </pre>
  788. <p id="compose">
  789. <b class="header">compose</b><code>_.compose(*functions)</code>
  790. <br />
  791. Returns the composition of a list of <b>functions</b>, where each function
  792. consumes the return value of the function that follows. In math terms,
  793. composing the functions <i>f()</i>, <i>g()</i>, and <i>h()</i> produces
  794. <i>f(g(h()))</i>.
  795. </p>
  796. <pre>
  797. var greet = function(name){ return "hi: " + name; };
  798. var exclaim = function(statement){ return statement + "!"; };
  799. var welcome = _.compose(exclaim, greet);
  800. welcome('moe');
  801. =&gt; 'hi: moe!'
  802. </pre>
  803. <h2>Object Functions</h2>
  804. <p id="keys">
  805. <b class="header">keys</b><code>_.keys(object)</code>
  806. <br />
  807. Retrieve all the names of the <b>object</b>'s properties.
  808. </p>
  809. <pre>
  810. _.keys({one : 1, two : 2, three : 3});
  811. =&gt; ["one", "two", "three"]
  812. </pre>
  813. <p id="values">
  814. <b class="header">values</b><code>_.values(object)</code>
  815. <br />
  816. Return all of the values of the <b>object</b>'s properties.
  817. </p>
  818. <pre>
  819. _.values({one : 1, two : 2, three : 3});
  820. =&gt; [1, 2, 3]
  821. </pre>
  822. <p id="functions">
  823. <b class="header">functions</b><code>_.functions(object)</code>
  824. <span class="alias">Alias: <b>methods</b></span>
  825. <br />
  826. Returns a sorted list of the names of every method in an object &mdash;
  827. that is to say, the name of every function property of the object.
  828. </p>
  829. <pre>
  830. _.functions(_);
  831. =&gt; ["all", "any", "bind", "bindAll", "clone", "compact", "compose" ...
  832. </pre>
  833. <p id="extend">
  834. <b class="header">extend</b><code>_.extend(destination, *sources)</code>
  835. <br />
  836. Copy all of the properties in the <b>source</b> objects over to the
  837. <b>destination</b> object. It's in-order, so the last source will override
  838. properties of the same name in previous arguments.
  839. </p>
  840. <pre>
  841. _.extend({name : 'moe'}, {age : 50});
  842. =&gt; {name : 'moe', age : 50}
  843. </pre>
  844. <p id="defaults">
  845. <b class="header">defaults</b><code>_.defaults(object, *defaults)</code>
  846. <br />
  847. Fill in missing properties in <b>object</b> with default values from the
  848. <b>defaults</b> objects. As soon as the property is filled, further defaults
  849. will have no effect.
  850. </p>
  851. <pre>
  852. var iceCream = {flavor : "chocolate"};
  853. _.defaults(iceCream, {flavor : "vanilla", sprinkles : "lots"});
  854. =&gt; {flavor : "chocolate", sprinkles : "lots"}
  855. </pre>
  856. <p id="clone">
  857. <b class="header">clone</b><code>_.clone(object)</code>
  858. <br />
  859. Create a shallow-copied clone of the <b>object</b>. Any nested objects
  860. or arrays will be copied by reference, not duplicated.
  861. </p>
  862. <pre>
  863. _.clone({name : 'moe'});
  864. =&gt; {name : 'moe'};
  865. </pre>
  866. <p id="tap">
  867. <b class="header">tap</b><code>_.tap(object, interceptor)</code>
  868. <br />
  869. Invokes <b>interceptor</b> with the <b>object</b>, and then returns <b>object</b>.
  870. The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
  871. </p>
  872. <pre>
  873. _([1,2,3,200]).chain().
  874. filter(function(num) { return num % 2 == 0; }).
  875. tap(console.log).
  876. map(function(num) { return num * num }).
  877. value();
  878. =&gt; [2, 200]
  879. =&gt; [4, 40000]
  880. </pre>
  881. <p id="isEqual">
  882. <b class="header">isEqual</b><code>_.isEqual(object, other)</code>
  883. <br />
  884. Performs an optimized deep comparison between the two objects, to determine
  885. if they should be considered equal.
  886. </p>
  887. <pre>
  888. var moe = {name : 'moe', luckyNumbers : [13, 27, 34]};
  889. var clone = {name : 'moe', luckyNumbers : [13, 27, 34]};
  890. moe == clone;
  891. =&gt; false
  892. _.isEqual(moe, clone);
  893. =&gt; true
  894. </pre>
  895. <p id="isEmpty">
  896. <b class="header">isEmpty</b><code>_.isEmpty(object)</code>
  897. <br />
  898. Returns <i>true</i> if <b>object</b> contains no values.
  899. </p>
  900. <pre>
  901. _.isEmpty([1, 2, 3]);
  902. =&gt; false
  903. _.isEmpty({});
  904. =&gt; true
  905. </pre>
  906. <p id="isElement">
  907. <b class="header">isElement</b><code>_.isElement(object)</code>
  908. <br />
  909. Returns <i>true</i> if <b>object</b> is a DOM element.
  910. </p>
  911. <pre>
  912. _.isElement(jQuery('body')[0]);
  913. =&gt; true
  914. </pre>
  915. <p id="isArray">
  916. <b class="header">isArray</b><code>_.isArray(object)</code>
  917. <br />
  918. Returns <i>true</i> if <b>object</b> is an Array.
  919. </p>
  920. <pre>
  921. (function(){ return _.isArray(arguments); })();
  922. =&gt; false
  923. _.isArray([1,2,3]);
  924. =&gt; true
  925. </pre>
  926. <p id="isArguments">
  927. <b class="header">isArguments</b><code>_.isArguments(object)</code>
  928. <br />
  929. Returns <i>true</i> if <b>object</b> is an Arguments object.
  930. </p>
  931. <pre>
  932. (function(){ return _.isArguments(arguments); })(1, 2, 3);
  933. =&gt; true
  934. _.isArguments([1,2,3]);
  935. =&gt; false
  936. </pre>
  937. <p id="isFunction">
  938. <b class="header">isFunction</b><code>_.isFunction(object)</code>
  939. <br />
  940. Returns <i>true</i> if <b>object</b> is a Function.
  941. </p>
  942. <pre>
  943. _.isFunction(alert);
  944. =&gt; true
  945. </pre>
  946. <p id="isString">
  947. <b class="header">isString</b><code>_.isString(object)</code>
  948. <br />
  949. Returns <i>true</i> if <b>object</b> is a String.
  950. </p>
  951. <pre>
  952. _.isString("moe");
  953. =&gt; true
  954. </pre>
  955. <p id="isNumber">
  956. <b class="header">isNumber</b><code>_.isNumber(object)</code>
  957. <br />
  958. Returns <i>true</i> if <b>object</b> is a Number.
  959. </p>
  960. <pre>
  961. _.isNumber(8.4 * 5);
  962. =&gt; true
  963. </pre>
  964. <p id="isBoolean">
  965. <b class="header">isBoolean</b><code>_.isBoolean(object)</code>
  966. <br />
  967. Returns <i>true</i> if <b>object</b> is either <i>true</i> or <i>false</i>.
  968. </p>
  969. <pre>
  970. _.isBoolean(null);
  971. =&gt; false
  972. </pre>
  973. <p id="isDate">
  974. <b class="header">isDate</b><code>_.isDate(object)</code>
  975. <br />
  976. Returns <i>true</i> if <b>object</b> is a Date.
  977. </p>
  978. <pre>
  979. _.isDate(new Date());
  980. =&gt; true
  981. </pre>
  982. <p id="isRegExp">
  983. <b class="header">isRegExp</b><code>_.isRegExp(object)</code>
  984. <br />
  985. Returns <i>true</i> if <b>object</b> is a RegExp.
  986. </p>
  987. <pre>
  988. _.isRegExp(/moe/);
  989. =&gt; true
  990. </pre>
  991. <p id="isNaN">
  992. <b class="header">isNaN</b><code>_.isNaN(object)</code>
  993. <br />
  994. Returns <i>true</i> if <b>object</b> is <i>NaN</i>.<br /> Note: this is not
  995. the same as the native <b>isNaN</b> function, which will also return
  996. true if the variable is <i>undefined</i>.
  997. </p>
  998. <pre>
  999. _.isNaN(NaN);
  1000. =&gt; true
  1001. isNaN(undefined);
  1002. =&gt; true
  1003. _.isNaN(undefined);
  1004. =&gt; false
  1005. </pre>
  1006. <p id="isNull">
  1007. <b class="header">isNull</b><code>_.isNull(object)</code>
  1008. <br />
  1009. Returns <i>true</i> if the value of <b>object</b> is <i>null</i>.
  1010. </p>
  1011. <pre>
  1012. _.isNull(null);
  1013. =&gt; true
  1014. _.isNull(undefined);
  1015. =&gt; false
  1016. </pre>
  1017. <p id="isUndefined">
  1018. <b class="header">isUndefined</b><code>_.isUndefined(variable)</code>
  1019. <br />
  1020. Returns <i>true</i> if <b>variable</b> is <i>undefined</i>.
  1021. </p>
  1022. <pre>
  1023. _.isUndefined(window.missingVariable);
  1024. =&gt; true
  1025. </pre>
  1026. <h2>Utility Functions</h2>
  1027. <p id="noConflict">
  1028. <b class="header">noConflict</b><code>_.noConflict()</code>
  1029. <br />
  1030. Give control of the "_" variable back to its previous owner. Returns
  1031. a reference to the <b>Underscore</b> object.
  1032. </p>
  1033. <pre>
  1034. var underscore = _.noConflict();</pre>
  1035. <p id="identity">
  1036. <b class="header">identity</b><code>_.identity(value)</code>
  1037. <br />
  1038. Returns the same value that is used as the argument. In math:
  1039. <tt>f(x) = x</tt><br />
  1040. This function looks useless, but is used throughout Underscore as
  1041. a default iterator.
  1042. </p>
  1043. <pre>
  1044. var moe = {name : 'moe'};
  1045. moe === _.identity(moe);
  1046. =&gt; true</pre>
  1047. <p id="times">
  1048. <b class="header">times</b><code>_.times(n, iterator)</code>
  1049. <br />
  1050. Invokes the given iterator function <b>n</b> times.
  1051. </p>
  1052. <pre>
  1053. _(3).times(function(){ genie.grantWish(); });</pre>
  1054. <p id="mixin">
  1055. <b class="header">mixin</b><code>_.mixin(object)</code>
  1056. <br />
  1057. Allows you to extend Underscore with your own utility functions. Pass
  1058. a hash of <tt>{name: function}</tt> definitions to have your functions
  1059. added to the Underscore object, as well as the OOP wrapper.
  1060. </p>
  1061. <pre>
  1062. _.mixin({
  1063. capitalize : function(string) {
  1064. return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase();
  1065. }
  1066. });
  1067. _("fabio").capitalize();
  1068. =&gt; "Fabio"
  1069. </pre>
  1070. <p id="uniqueId">
  1071. <b class="header">uniqueId</b><code>_.uniqueId([prefix])</code>
  1072. <br />
  1073. Generate a globally-unique id for client-side models or DOM elements
  1074. that need one. If <b>prefix</b> is passed, the id will be appended to it.
  1075. </p>
  1076. <pre>
  1077. _.uniqueId('contact_');
  1078. =&gt; 'contact_104'</pre>
  1079. <p id="escape">
  1080. <b class="header">escape</b><code>_.escape(string)</code>
  1081. <br />
  1082. Escapes a string for insertion into HTML, replacing
  1083. <tt>&amp;</tt>, <tt>&lt;</tt>, <tt>&gt;</tt>, <tt>&quot;</tt>, <tt>&#x27;</tt>, and <tt>&#x2F;</tt> characters.
  1084. </p>
  1085. <pre>
  1086. _.escape('Curly, Larry &amp; Moe');
  1087. =&gt; "Curly, Larry &amp;amp; Moe"</pre>
  1088. <p id="template">
  1089. <b class="header">template</b><code>_.template(templateString, [context])</code>
  1090. <br />
  1091. Compiles JavaScript templates into functions that can be evaluated
  1092. for rendering. Useful for rendering complicated bits of HTML from JSON
  1093. data sources. Template functions can both interpolate variables, using<br />
  1094. <tt>&lt;%= &hellip; %&gt;</tt>, as well as execute arbitrary JavaScript code, with
  1095. <tt>&lt;% &hellip; %&gt;</tt>. If you wish to interpolate a value, and have
  1096. it be HTML-escaped, use <tt>&lt;%- &hellip; %&gt;</tt> When you evaluate a template function, pass in a
  1097. <b>context</b> object that has properties corresponding to the template's free
  1098. variables. If you're writing a one-off, you can pass the <b>context</b>
  1099. object as the second parameter to <b>template</b> in order to render
  1100. immediately instead of returning a template function.
  1101. </p>
  1102. <pre>
  1103. var compiled = _.template("hello: &lt;%= name %&gt;");
  1104. compiled({name : 'moe'});
  1105. =&gt; "hello: moe"
  1106. var list = "&lt;% _.each(people, function(name) { %&gt; &lt;li&gt;&lt;%= name %&gt;&lt;/li&gt; &lt;% }); %&gt;";
  1107. _.template(list, {people : ['moe', 'curly', 'larry']});
  1108. =&gt; "&lt;li&gt;moe&lt;/li&gt;&lt;li&gt;curly&lt;/li&gt;&lt;li&gt;larry&lt;/li&gt;"
  1109. var template = _.template("&lt;b&gt;&lt;%- value %&gt;&lt;/b&gt;");
  1110. template({value : '&lt;script&gt;'});
  1111. =&gt; "&lt;b&gt;&amp;lt;script&amp;gt;&lt;/b&gt;"</pre>
  1112. <p>
  1113. You can also use <tt>print</tt> from within JavaScript code. This is
  1114. sometimes more convenient than using <tt>&lt;%= ... %&gt;</tt>.
  1115. </p>
  1116. <pre>
  1117. var compiled = _.template("&lt;% print('Hello ' + epithet); %&gt;");
  1118. compiled({epithet: "stooge"});
  1119. =&gt; "Hello stooge."</pre>
  1120. <p>
  1121. If ERB-style delimiters aren't your cup of tea, you can change Underscore's
  1122. template settings to use different symbols to set off interpolated code.
  1123. Define an <b>interpolate</b> regex, and an (optional) <b>evaluate</b> regex
  1124. to match expressions that should be inserted and evaluated, respectively.
  1125. If no <b>evaluate</b> regex is provided, your templates will only be
  1126. capable of interpolating values.
  1127. For example, to perform
  1128. <a href="http://github.com/janl/mustache.js#readme">Mustache.js</a>
  1129. style templating:
  1130. </p>
  1131. <pre>
  1132. _.templateSettings = {
  1133. interpolate : /\{\{(.+?)\}\}/g
  1134. };
  1135. var template = _.template("Hello {{ name }}!");
  1136. template({name : "Mustache"});
  1137. =&gt; "Hello Mustache!"</pre>
  1138. <h2>Chaining</h2>
  1139. <p id="chain">
  1140. <b class="header">chain</b><code>_(obj).chain()</code>
  1141. <br />
  1142. Returns a wrapped object. Calling methods on this object will continue
  1143. to return wrapped objects until <tt>value</tt> is used. (
  1144. <a href="#styles">A more realistic example.</a>)
  1145. </p>
  1146. <pre>
  1147. var stooges = [{name : 'curly', age : 25}, {name : 'moe', age : 21}, {name : 'larry', age : 23}];
  1148. var youngest = _(stooges).chain()
  1149. .sortBy(function(stooge){ return stooge.age; })
  1150. .map(function(stooge){ return stooge.name + ' is ' + stooge.age; })
  1151. .first()
  1152. .value();
  1153. =&gt; "moe is 21"
  1154. </pre>
  1155. <p id="value">
  1156. <b class="header">value</b><code>_(obj).value()</code>
  1157. <br />
  1158. Extracts the value of a wrapped object.
  1159. </p>
  1160. <pre>
  1161. _([1, 2, 3]).value();
  1162. =&gt; [1, 2, 3]
  1163. </pre>
  1164. <h2>Links &amp; Suggested Reading</h2>
  1165. <p>
  1166. <a href="http://mirven.github.com/underscore.lua/">Underscore.lua</a>,
  1167. a Lua port of the functions that are applicable in both languages.
  1168. Includes OOP-wrapping and chaining.
  1169. The <a href="http://github.com/mirven/underscore.lua">source</a> is
  1170. available on GitHub.
  1171. </p>
  1172. <p>
  1173. <a href="http://brianhaveri.github.com/Underscore.php/">Underscore.php</a>,
  1174. a PHP port of the functions that are applicable in both languages.
  1175. Includes OOP-wrapping and chaining.
  1176. The <a href="http://github.com/brianhaveri/Underscore.php">source</a> is
  1177. available on GitHub.
  1178. </p>
  1179. <p>
  1180. <a href="http://vti.github.com/underscore-perl/">Underscore-perl</a>,
  1181. a Perl port of many of the Underscore.js functions,
  1182. aimed at on Perl hashes and arrays, also
  1183. <a href="https://github.com/vti/underscore-perl/">available on GitHub</a>.
  1184. </p>
  1185. <p>
  1186. <a href="https://github.com/edtsech/underscore.string">Underscore.string</a>,
  1187. an Underscore extension that adds functions for string-manipulation:
  1188. <tt>trim</tt>, <tt>startsWith</tt>, <tt>contains</tt>, <tt>capitalize</tt>,
  1189. <tt>reverse</tt>, <tt>sprintf</tt>, and more.
  1190. </p>
  1191. <p>
  1192. Ruby's <a href="http://ruby-doc.org/core/classes/Enumerable.html">Enumerable</a> module.
  1193. </p>
  1194. <p>
  1195. <a href="http://www.prototypejs.org/">Prototype.js</a>, which provides
  1196. JavaScript with collection functions in the manner closest to Ruby's Enumerable.
  1197. </p>
  1198. <p>
  1199. Oliver Steele's
  1200. <a href="http://osteele.com/sources/javascript/functional/">Functional JavaScript</a>,
  1201. which includes comprehensive higher-order function support as well as string lambdas.
  1202. </p>
  1203. <p>
  1204. Michael Aufreiter's <a href="http://substance.io/#michael/data-js">Data.js</a>,
  1205. a data manipulation + persistence library for JavaScript.
  1206. </p>
  1207. <p>
  1208. Python's <a href="http://docs.python.org/library/itertools.html">itertools</a>.
  1209. </p>
  1210. <h2 id="changelog">Change Log</h2>
  1211. <p>
  1212. <b class="header">1.2.3</b> &mdash; <small><i>Dec. 7, 2011</i></small><br />
  1213. <ul>
  1214. <li>
  1215. Dynamic scope is now preserved for compiled <tt>_.template</tt> functions,
  1216. so you can use the value of <tt>this</tt> if you like.
  1217. </li>
  1218. <li>
  1219. Sparse array support of <tt>_.indexOf</tt>, <tt>_.lastIndexOf</tt>.
  1220. </li>
  1221. <li>
  1222. Both <tt>_.reduce</tt> and <tt>_.reduceRight</tt> can now be passed an
  1223. explicitly <tt>undefined</tt> value. (There's no reason why you'd
  1224. want to do this.)
  1225. </li>
  1226. </ul>
  1227. </p>
  1228. <p>
  1229. <b class="header">1.2.2</b> &mdash; <small><i>Nov. 14, 2011</i></small><br />
  1230. <ul>
  1231. <li>
  1232. Continued tweaks to <tt>_.isEqual</tt> semantics. Now JS primitives are
  1233. considered equivalent to their wrapped versions, and arrays are compared
  1234. by their numeric properties only <small>(#351)</small>.
  1235. </li>
  1236. <li>
  1237. <tt>_.escape</tt> no longer tries to be smart about not double-escaping
  1238. already-escaped HTML entities. Now it just escapes regardless <small>(#350)</small>.
  1239. </li>
  1240. <li>
  1241. In <tt>_.template</tt>, you may now leave semicolons out of evaluated
  1242. statements if you wish: <tt>&lt;% }) %&gt;</tt> <small>(#369)</small>.
  1243. </li>
  1244. <li>
  1245. <tt>_.after(callback, 0)</tt> will now trigger the callback immediately,
  1246. making "after" easier to use with asynchronous APIs <small>(#366)</small>.
  1247. </li>
  1248. </ul>
  1249. </p>
  1250. <p>
  1251. <b class="header">1.2.1</b> &mdash; <small><i>Oct. 24, 2011</i></small><br />
  1252. <ul>
  1253. <li>
  1254. Several important bug fixes for <tt>_.isEqual</tt>, which should now
  1255. do better on mutated Arrays, and on non-Array objects with
  1256. <tt>length</tt> properties. <small>(#329)</small>
  1257. </li>
  1258. <li>
  1259. <b>jrburke</b> contributed Underscore exporting for AMD module loaders,
  1260. and <b>tonylukasavage</b> for Appcelerator Titanium.
  1261. <small>(#335, #338)</small>
  1262. </li>
  1263. <li>
  1264. You can now <tt>_.groupBy(list, 'property')</tt> as a shortcut for
  1265. grouping values by a particular common property.
  1266. </li>
  1267. <li>
  1268. <tt>_.throttle</tt>'d functions now fire immediately upon invocation,
  1269. and are rate-limited thereafter <small>(#170, #266)</small>.
  1270. </li>
  1271. <li>
  1272. Most of the <tt>_.is[Type]</tt> checks no longer ducktype.
  1273. </li>
  1274. <li>
  1275. The <tt>_.bind</tt> function now also works on constructors, a-la
  1276. ES5 ... but you would never want to use <tt>_.bind</tt> on a
  1277. constructor function.
  1278. </li>
  1279. <li>
  1280. <tt>_.clone</tt> no longer wraps non-object types in Objects.
  1281. </li>
  1282. <li>
  1283. <tt>_.find</tt> and <tt>_.filter</tt> are now the preferred names for
  1284. <tt>_.detect</tt> and <tt>_.select</tt>.
  1285. </li>
  1286. </ul>
  1287. </p>
  1288. <p>
  1289. <b class="header">1.2.0</b> &mdash; <small><i>Oct. 5, 2011</i></small><br />
  1290. <ul>
  1291. <li>
  1292. The <tt>_.isEqual</tt> function now
  1293. supports true deep equality comparisons, with checks for cyclic structures,
  1294. thanks to Kit Cambridge.
  1295. </li>
  1296. <li>
  1297. Underscore templates now support HTML escaping interpolations, using
  1298. <tt>&lt;%- ... %&gt;</tt> syntax.
  1299. </li>
  1300. <li>
  1301. Ryan Tenney contributed <tt>_.shuffle</tt>, which uses a modified
  1302. Fisher-Yates to give you a shuffled copy of an array.
  1303. </li>
  1304. <li>
  1305. <tt>_.uniq</tt> can now be passed an optional iterator, to determine by
  1306. what criteria an object should be considered unique.
  1307. </li>
  1308. <li>
  1309. <tt>_.last</tt> now takes an optional argument which will return the last
  1310. N elements of the list.
  1311. </li>
  1312. <li>
  1313. A new <tt>_.initial</tt> function was added, as a mirror of <tt>_.rest</tt>,
  1314. which returns all the initial values of a list (except the last N).
  1315. </li>
  1316. </ul>
  1317. </p>
  1318. <p>
  1319. <b class="header">1.1.7</b> &mdash; <small><i>July 13, 2011</i></small><br />
  1320. Added <tt>_.groupBy</tt>, which aggregates a collection into groups of like items.
  1321. Added <tt>_.union</tt> and <tt>_.difference</tt>, to complement the
  1322. (re-named) <tt>_.intersection</tt>.
  1323. Various improvements for support of sparse arrays.
  1324. <tt>_.toArray</tt> now returns a clone, if directly passed an array.
  1325. <tt>_.functions</tt> now also returns the names of functions that are present
  1326. in the prototype chain.
  1327. </p>
  1328. <p>
  1329. <b class="header">1.1.6</b> &mdash; <small><i>April 18, 2011</i></small><br />
  1330. Added <tt>_.after</tt>, which will return a function that only runs after
  1331. first being called a specified number of times.
  1332. <tt>_.invoke</tt> can now take a direct function reference.
  1333. <tt>_.every</tt> now requires an iterator function to be passed, which
  1334. mirrors the ECMA5 API.
  1335. <tt>_.extend</tt> no longer copies keys when the value is undefined.
  1336. <tt>_.bind</tt> now errors when trying to bind an undefined value.
  1337. </p>
  1338. <p>
  1339. <b class="header">1.1.5</b> &mdash; <small><i>Mar 20, 2011</i></small><br />
  1340. Added an <tt>_.defaults</tt> function, for use merging together JS objects
  1341. representing default options.
  1342. Added an <tt>_.once</tt> function, for manufacturing functions that should
  1343. only ever execute a single time.
  1344. <tt>_.bind</tt> now delegates to the native ECMAScript 5 version,
  1345. where available.
  1346. <tt>_.keys</tt> now throws an error when used on non-Object values, as in
  1347. ECMAScript 5.
  1348. Fixed a bug with <tt>_.keys</tt> when used over sparse arrays.
  1349. </p>
  1350. <p>
  1351. <b class="header">1.1.4</b> &mdash; <small><i>Jan 9, 2011</i></small><br />
  1352. Improved compliance with ES5's Array methods when passing <tt>null</tt>
  1353. as a value. <tt>_.wrap</tt> now correctly sets <tt>this</tt> for the
  1354. wrapped function. <tt>_.indexOf</tt> now takes an optional flag for
  1355. finding the insertion index in an array that is guaranteed to already
  1356. be sorted. Avoiding the use of <tt>.callee</tt>, to allow <tt>_.isArray</tt>
  1357. to work properly in ES5's strict mode.
  1358. </p>
  1359. <p>
  1360. <b class="header">1.1.3</b> &mdash; <small><i>Dec 1, 2010</i></small><br />
  1361. In CommonJS, Underscore may now be required with just: <br />
  1362. <tt>var _ = require("underscore")</tt>.
  1363. Added <tt>_.throttle</tt> and <tt>_.debounce</tt> functions.
  1364. Removed <tt>_.breakLoop</tt>, in favor of an ECMA5-style un-<i>break</i>-able
  1365. each implementation &mdash; this removes the try/catch, and you'll now have
  1366. better stack traces for exceptions that are thrown within an Underscore iterator.
  1367. Improved the <b>isType</b> family of functions for better interoperability
  1368. with Internet Explorer host objects.
  1369. <tt>_.template</tt> now correctly escapes backslashes in templates.
  1370. Improved <tt>_.reduce</tt> compatibility with the ECMA5 version:
  1371. if you don't pass an initial value, the first item in the collection is used.
  1372. <tt>_.each</tt> no longer returns the iterated collection, for improved
  1373. consistency with ES5's <tt>forEach</tt>.
  1374. </p>
  1375. <p>
  1376. <b class="header">1.1.2</b><br />
  1377. Fixed <tt>_.contains</tt>, which was mistakenly pointing at
  1378. <tt>_.intersect</tt> instead of <tt>_.include</tt>, like it should
  1379. have been. Added <tt>_.unique</tt> as an alias for <tt>_.uniq</tt>.
  1380. </p>
  1381. <p>
  1382. <b class="header">1.1.1</b><br />
  1383. Improved the speed of <tt>_.template</tt>, and its handling of multiline
  1384. interpolations. Ryan Tenney contributed optimizations to many Underscore
  1385. functions. An annotated version of the source code is now available.
  1386. </p>
  1387. <p>
  1388. <b class="header">1.1.0</b><br />
  1389. The method signature of <tt>_.reduce</tt> has been changed to match
  1390. the ECMAScript 5 signature, instead of the Ruby/Prototype.js version.
  1391. This is a backwards-incompatible change. <tt>_.template</tt> may now be
  1392. called with no arguments, and preserves whitespace. <tt>_.contains</tt>
  1393. is a new alias for <tt>_.include</tt>.
  1394. </p>
  1395. <p>
  1396. <b class="header">1.0.4</b><br />
  1397. <a href="http://themoell.com/">Andri Möll</a> contributed the <tt>_.memoize</tt>
  1398. function, which can be used to speed up expensive repeated computations
  1399. by caching the results.
  1400. </p>
  1401. <p>
  1402. <b class="header">1.0.3</b><br />
  1403. Patch that makes <tt>_.isEqual</tt> return <tt>false</tt> if any property
  1404. of the compared object has a <tt>NaN</tt> value. Technically the correct
  1405. thing to do, but of questionable semantics. Watch out for NaN comparisons.
  1406. </p>
  1407. <p>
  1408. <b class="header">1.0.2</b><br />
  1409. Fixes <tt>_.isArguments</tt> in recent versions of Opera, which have
  1410. arguments objects as real Arrays.
  1411. </p>
  1412. <p>
  1413. <b class="header">1.0.1</b><br />
  1414. Bugfix for <tt>_.isEqual</tt>, when comparing two objects with the same
  1415. number of undefined keys, but with different names.
  1416. </p>
  1417. <p>
  1418. <b class="header">1.0.0</b><br />
  1419. Things have been stable for many months now, so Underscore is now
  1420. considered to be out of beta, at <b>1.0</b>. Improvements since <b>0.6</b>
  1421. include <tt>_.isBoolean</tt>, and the ability to have <tt>_.extend</tt>
  1422. take multiple source objects.
  1423. </p>
  1424. <p>
  1425. <b class="header">0.6.0</b><br />
  1426. Major release. Incorporates a number of
  1427. <a href="http://github.com/ratbeard">Mile Frawley's</a> refactors for
  1428. safer duck-typing on collection functions, and cleaner internals. A new
  1429. <tt>_.mixin</tt> method that allows you to extend Underscore with utility
  1430. functions of your own. Added <tt>_.times</tt>, which works the same as in
  1431. Ruby or Prototype.js. Native support for ECMAScript 5's <tt>Array.isArray</tt>,
  1432. and <tt>Object.keys</tt>.
  1433. </p>
  1434. <p>
  1435. <b class="header">0.5.8</b><br />
  1436. Fixed Underscore's collection functions to work on
  1437. <a href="https://developer.mozilla.org/En/DOM/NodeList">NodeLists</a> and
  1438. <a href="https://developer.mozilla.org/En/DOM/HTMLCollection">HTMLCollections</a>
  1439. once more, thanks to
  1440. <a href="http://github.com/jmtulloss">Justin Tulloss</a>.
  1441. </p>
  1442. <p>
  1443. <b class="header">0.5.7</b><br />
  1444. A safer implementation of <tt>_.isArguments</tt>, and a
  1445. faster <tt>_.isNumber</tt>,<br />thanks to
  1446. <a href="http://jedschmidt.com/">Jed Schmidt</a>.
  1447. </p>
  1448. <p>
  1449. <b class="header">0.5.6</b><br />
  1450. Customizable delimiters for <tt>_.template</tt>, contributed by
  1451. <a href="http://github.com/iamnoah">Noah Sloan</a>.
  1452. </p>
  1453. <p>
  1454. <b class="header">0.5.5</b><br />
  1455. Fix for a bug in MobileSafari's OOP-wrapper, with the arguments object.
  1456. </p>
  1457. <p>
  1458. <b class="header">0.5.4</b><br />
  1459. Fix for multiple single quotes within a template string for
  1460. <tt>_.template</tt>. See:
  1461. <a href="http://www.west-wind.com/Weblog/posts/509108.aspx">Rick Strahl's blog post</a>.
  1462. </p>
  1463. <p>
  1464. <b class="header">0.5.2</b><br />
  1465. New implementations of <tt>isArray</tt>, <tt>isDate</tt>, <tt>isFunction</tt>,
  1466. <tt>isNumber</tt>, <tt>isRegExp</tt>, and <tt>isString</tt>, thanks to
  1467. a suggestion from
  1468. <a href="http://www.broofa.com/">Robert Kieffer</a>.
  1469. Instead of doing <tt>Object#toString</tt>
  1470. comparisons, they now check for expected properties, which is less safe,
  1471. but more than an order of magnitude faster. Most other Underscore
  1472. functions saw minor speed improvements as a result.
  1473. <a href="http://dolzhenko.org/">Evgeniy Dolzhenko</a>
  1474. contributed <tt>_.tap</tt>,
  1475. <a href="http://ruby-doc.org/core-1.9/classes/Object.html#M000191">similar to Ruby 1.9's</a>,
  1476. which is handy for injecting side effects (like logging) into chained calls.
  1477. </p>
  1478. <p>
  1479. <b class="header">0.5.1</b><br />
  1480. Added an <tt>_.isArguments</tt> function. Lots of little safety checks
  1481. and optimizations contributed by
  1482. <a href="http://github.com/iamnoah/">Noah Sloan</a> and
  1483. <a href="http://themoell.com/">Andri Möll</a>.
  1484. </p>
  1485. <p>
  1486. <b class="header">0.5.0</b><br />
  1487. <b>[API Changes]</b> <tt>_.bindAll</tt> now takes the context object as
  1488. its first parameter. If no method names are passed, all of the context
  1489. object's methods are bound to it, enabling chaining and easier binding.
  1490. <tt>_.functions</tt> now takes a single argument and returns the names
  1491. of its Function properties. Calling <tt>_.functions(_)</tt> will get you
  1492. the previous behavior.
  1493. Added <tt>_.isRegExp</tt> so that <tt>isEqual</tt> can now test for RegExp equality.
  1494. All of the "is" functions have been shrunk down into a single definition.
  1495. <a href="http://github.com/grayrest/">Karl Guertin</a> contributed patches.
  1496. </p>
  1497. <p>
  1498. <b class="header">0.4.7</b><br />
  1499. Added <tt>isDate</tt>, <tt>isNaN</tt>, and <tt>isNull</tt>, for completeness.
  1500. Optimizations for <tt>isEqual</tt> when checking equality between Arrays
  1501. or Dates. <tt>_.keys</tt> is now <small><i><b>25%&ndash;2X</b></i></small> faster (depending on your
  1502. browser) which speeds up the functions that rely on it, such as <tt>_.each</tt>.
  1503. </p>
  1504. <p>
  1505. <b class="header">0.4.6</b><br />
  1506. Added the <tt>range</tt> function, a port of the
  1507. <a href="http://docs.python.org/library/functions.html#range">Python
  1508. function of the same name</a>, for generating flexibly-numbered lists
  1509. of integers. Original patch contributed by
  1510. <a href="http://github.com/kylichuku">Kirill Ishanov</a>.
  1511. </p>
  1512. <p>
  1513. <b class="header">0.4.5</b><br />
  1514. Added <tt>rest</tt> for Arrays and arguments objects, and aliased
  1515. <tt>first</tt> as <tt>head</tt>, and <tt>rest</tt> as <tt>tail</tt>,
  1516. thanks to <a href="http://github.com/lukesutton/">Luke Sutton</a>'s patches.
  1517. Added tests ensuring that all Underscore Array functions also work on
  1518. <i>arguments</i> objects.
  1519. </p>
  1520. <p>
  1521. <b class="header">0.4.4</b><br />
  1522. Added <tt>isString</tt>, and <tt>isNumber</tt>, for consistency. Fixed
  1523. <tt>_.isEqual(NaN, NaN)</tt> to return <i>true</i> (which is debatable).
  1524. </p>
  1525. <p>
  1526. <b class="header">0.4.3</b><br />
  1527. Started using the native <tt>StopIteration</tt> object in browsers that support it.
  1528. Fixed Underscore setup for CommonJS environments.
  1529. </p>
  1530. <p>
  1531. <b class="header">0.4.2</b><br />
  1532. Renamed the unwrapping function to <tt>value</tt>, for clarity.
  1533. </p>
  1534. <p>
  1535. <b class="header">0.4.1</b><br />
  1536. Chained Underscore objects now support the Array prototype methods, so
  1537. that you can perform the full range of operations on a wrapped array
  1538. without having to break your chain. Added a <tt>breakLoop</tt> method
  1539. to <b>break</b> in the middle of any Underscore iteration. Added an
  1540. <tt>isEmpty</tt> function that works on arrays and objects.
  1541. </p>
  1542. <p>
  1543. <b class="header">0.4.0</b><br />
  1544. All Underscore functions can now be called in an object-oriented style,
  1545. like so: <tt>_([1, 2, 3]).map(...);</tt>. Original patch provided by
  1546. <a href="http://macournoyer.com/">Marc-André Cournoyer</a>.
  1547. Wrapped objects can be chained through multiple
  1548. method invocations. A <a href="#functions"><tt>functions</tt></a> method
  1549. was added, providing a sorted list of all the functions in Underscore.
  1550. </p>
  1551. <p>
  1552. <b class="header">0.3.3</b><br />
  1553. Added the JavaScript 1.8 function <tt>reduceRight</tt>. Aliased it
  1554. as <tt>foldr</tt>, and aliased <tt>reduce</tt> as <tt>foldl</tt>.
  1555. </p>
  1556. <p>
  1557. <b class="header">0.3.2</b><br />
  1558. Now runs on stock <a href="http://www.mozilla.org/rhino/">Rhino</a>
  1559. interpreters with: <tt>load("underscore.js")</tt>.
  1560. Added <a href="#identity"><tt>identity</tt></a> as a utility function.
  1561. </p>
  1562. <p>
  1563. <b class="header">0.3.1</b><br />
  1564. All iterators are now passed in the original collection as their third
  1565. argument, the same as JavaScript 1.6's <b>forEach</b>. Iterating over
  1566. objects is now called with <tt>(value, key, collection)</tt>, for details
  1567. see <a href="#each"><tt>_.each</tt></a>.
  1568. </p>
  1569. <p>
  1570. <b class="header">0.3.0</b><br />
  1571. Added <a href="http://github.com/dmitryBaranovskiy">Dmitry Baranovskiy</a>'s
  1572. comprehensive optimizations, merged in
  1573. <a href="http://github.com/kriskowal/">Kris Kowal</a>'s patches to make Underscore
  1574. <a href="http://wiki.commonjs.org/wiki/CommonJS">CommonJS</a> and
  1575. <a href="http://narwhaljs.org/">Narwhal</a> compliant.
  1576. </p>
  1577. <p>
  1578. <b class="header">0.2.0</b><br />
  1579. Added <tt>compose</tt> and <tt>lastIndexOf</tt>, renamed <tt>inject</tt> to
  1580. <tt>reduce</tt>, added aliases for <tt>inject</tt>, <tt>filter</tt>,
  1581. <tt>every</tt>, <tt>some</tt>, and <tt>forEach</tt>.
  1582. </p>
  1583. <p>
  1584. <b class="header">0.1.1</b><br />
  1585. Added <tt>noConflict</tt>, so that the "Underscore" object can be assigned to
  1586. other variables.
  1587. </p>
  1588. <p>
  1589. <b class="header">0.1.0</b><br />
  1590. Initial release of Underscore.js.
  1591. </p>
  1592. <p>
  1593. <a href="http://documentcloud.org/" title="A DocumentCloud Project" style="background:none;">
  1594. <img src="http://jashkenas.s3.amazonaws.com/images/a_documentcloud_project.png" alt="A DocumentCloud Project" />
  1595. </a>
  1596. </p>
  1597. </div>
  1598. </div>
  1599. <!-- Include Underscore, so you can play with it in the console. -->
  1600. <script type="text/javascript" src="underscore.js"></script>
  1601. </body>
  1602. </html>