PageRenderTime 67ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/underscore/index.html

https://bitbucket.org/worldsayshi/master_thesis-gui
HTML | 2382 lines | 2168 code | 213 blank | 1 comment | 0 complexity | 6a23b26a6763122aa1bebc1d2f157396 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. <meta name="viewport" content="width=device-width" />
  7. <link rel="canonical" href="http://underscorejs.org" />
  8. <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
  9. <title>Underscore.js</title>
  10. <style>
  11. body {
  12. font-size: 14px;
  13. line-height: 22px;
  14. background: #f4f4f4 url(docs/images/background.png);
  15. color: #000;
  16. font-family: Helvetica Neue, Helvetica, Arial;
  17. }
  18. .interface {
  19. font-family: "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, sans-serif !important;
  20. }
  21. div#sidebar {
  22. background: #fff;
  23. position: fixed;
  24. top: 0; left: 0; bottom: 0;
  25. width: 200px;
  26. overflow-y: auto;
  27. overflow-x: hidden;
  28. -webkit-overflow-scrolling: touch;
  29. padding: 15px 0 30px 30px;
  30. border-right: 1px solid #bbb;
  31. box-shadow: 0 0 20px #ccc; -webkit-box-shadow: 0 0 20px #ccc; -moz-box-shadow: 0 0 20px #ccc;
  32. }
  33. a.toc_title, a.toc_title:visited {
  34. display: block;
  35. color: black;
  36. font-weight: bold;
  37. margin-top: 15px;
  38. }
  39. a.toc_title:hover {
  40. text-decoration: underline;
  41. }
  42. #sidebar .version {
  43. font-size: 10px;
  44. font-weight: normal;
  45. }
  46. ul.toc_section {
  47. font-size: 11px;
  48. line-height: 14px;
  49. margin: 5px 0 0 0;
  50. padding-left: 0px;
  51. list-style-type: none;
  52. font-family: Lucida Grande;
  53. }
  54. .toc_section li {
  55. cursor: pointer;
  56. margin: 0 0 3px 0;
  57. }
  58. .toc_section li a {
  59. text-decoration: none;
  60. color: black;
  61. }
  62. .toc_section li a:hover {
  63. text-decoration: underline;
  64. }
  65. div.container {
  66. width: 550px;
  67. margin: 40px 0 50px 260px;
  68. }
  69. img#logo {
  70. width: 396px;
  71. height: 69px;
  72. }
  73. div.warning {
  74. margin-top: 15px;
  75. font: bold 11px Arial;
  76. color: #770000;
  77. }
  78. p {
  79. margin: 20px 0;
  80. width: 550px;
  81. }
  82. a, a:visited {
  83. color: #444;
  84. }
  85. a:active, a:hover {
  86. color: #000;
  87. }
  88. h1, h2, h3, h4, h5, h6 {
  89. padding-top: 20px;
  90. }
  91. h2 {
  92. font-size: 20px;
  93. }
  94. b.header {
  95. font-size: 16px;
  96. line-height: 30px;
  97. }
  98. span.alias {
  99. font-size: 14px;
  100. font-style: italic;
  101. margin-left: 20px;
  102. }
  103. table, tr, td {
  104. margin: 0; padding: 0;
  105. }
  106. td {
  107. padding: 2px 12px 2px 0;
  108. }
  109. table .rule {
  110. height: 1px;
  111. background: #ccc;
  112. margin: 5px 0;
  113. }
  114. ul {
  115. list-style-type: circle;
  116. padding: 0 0 0 20px;
  117. }
  118. li {
  119. width: 500px;
  120. margin-bottom: 10px;
  121. }
  122. code, pre, tt {
  123. font-family: Monaco, Consolas, "Lucida Console", monospace;
  124. font-size: 12px;
  125. line-height: 18px;
  126. font-style: normal;
  127. }
  128. tt {
  129. padding: 0px 3px;
  130. background: #fff;
  131. border: 1px solid #ddd;
  132. zoom: 1;
  133. }
  134. code {
  135. margin-left: 20px;
  136. }
  137. pre {
  138. font-size: 12px;
  139. padding: 2px 0 2px 15px;
  140. border-left: 5px solid #bbb;
  141. margin: 0px 0 30px;
  142. }
  143. @media only screen and (-webkit-min-device-pixel-ratio: 1.5) and (max-width: 640px),
  144. only screen and (-o-min-device-pixel-ratio: 3/2) and (max-width: 640px),
  145. only screen and (min-device-pixel-ratio: 1.5) and (max-width: 640px) {
  146. img {
  147. max-width: 100%;
  148. }
  149. div#sidebar {
  150. -webkit-overflow-scrolling: initial;
  151. position: relative;
  152. width: 90%;
  153. height: 120px;
  154. left: 0;
  155. top: -7px;
  156. padding: 10px 0 10px 30px;
  157. border: 0;
  158. }
  159. img#logo {
  160. width: auto;
  161. height: auto;
  162. }
  163. div.container {
  164. margin: 0;
  165. width: 100%;
  166. }
  167. p, div.container ul {
  168. max-width: 98%;
  169. overflow-x: scroll;
  170. }
  171. pre {
  172. overflow: scroll;
  173. }
  174. }
  175. </style>
  176. </head>
  177. <body>
  178. <div id="sidebar" class="interface">
  179. <a class="toc_title" href="#">
  180. Underscore.js <span class="version">(1.4.2)</span>
  181. </a>
  182. <a class="toc_title" href="#">
  183. Introduction
  184. </a>
  185. <a class="toc_title" href="#collections">
  186. Collections
  187. </a>
  188. <ul class="toc_section">
  189. <li>- <a href="#each">each</a></li>
  190. <li>- <a href="#map">map</a></li>
  191. <li>- <a href="#reduce">reduce</a></li>
  192. <li>- <a href="#reduceRight">reduceRight</a></li>
  193. <li>- <a href="#find">find</a></li>
  194. <li>- <a href="#filter">filter</a></li>
  195. <li>- <a href="#where">where</a></li>
  196. <li>- <a href="#reject">reject</a></li>
  197. <li>- <a href="#every">every</a></li>
  198. <li>- <a href="#some">some</a></li>
  199. <li>- <a href="#contains">contains</a></li>
  200. <li>- <a href="#invoke">invoke</a></li>
  201. <li>- <a href="#pluck">pluck</a></li>
  202. <li>- <a href="#max">max</a></li>
  203. <li>- <a href="#min">min</a></li>
  204. <li>- <a href="#sortBy">sortBy</a></li>
  205. <li>- <a href="#groupBy">groupBy</a></li>
  206. <li>- <a href="#countBy">countBy</a></li>
  207. <li>- <a href="#shuffle">shuffle</a></li>
  208. <li>- <a href="#toArray">toArray</a></li>
  209. <li>- <a href="#size">size</a></li>
  210. </ul>
  211. <a class="toc_title" href="#arrays">
  212. Arrays
  213. </a>
  214. <ul class="toc_section">
  215. <li>- <a href="#first">first</a></li>
  216. <li>- <a href="#initial">initial</a></li>
  217. <li>- <a href="#last">last</a></li>
  218. <li>- <a href="#rest">rest</a></li>
  219. <li>- <a href="#compact">compact</a></li>
  220. <li>- <a href="#flatten">flatten</a></li>
  221. <li>- <a href="#without">without</a></li>
  222. <li>- <a href="#union">union</a></li>
  223. <li>- <a href="#intersection">intersection</a></li>
  224. <li>- <a href="#difference">difference</a></li>
  225. <li>- <a href="#uniq">uniq</a></li>
  226. <li>- <a href="#zip">zip</a></li>
  227. <li>- <a href="#object">object</a></li>
  228. <li>- <a href="#indexOf">indexOf</a></li>
  229. <li>- <a href="#lastIndexOf">lastIndexOf</a></li>
  230. <li>- <a href="#sortedIndex">sortedIndex</a></li>
  231. <li>- <a href="#range">range</a></li>
  232. </ul>
  233. <a class="toc_title" href="#functions">
  234. Functions
  235. </a>
  236. <ul class="toc_section">
  237. <li>- <a href="#bind">bind</a></li>
  238. <li>- <a href="#bindAll">bindAll</a></li>
  239. <li>- <a href="#memoize">memoize</a></li>
  240. <li>- <a href="#delay">delay</a></li>
  241. <li>- <a href="#defer">defer</a></li>
  242. <li>- <a href="#throttle">throttle</a></li>
  243. <li>- <a href="#debounce">debounce</a></li>
  244. <li>- <a href="#once">once</a></li>
  245. <li>- <a href="#after">after</a></li>
  246. <li>- <a href="#wrap">wrap</a></li>
  247. <li>- <a href="#compose">compose</a></li>
  248. </ul>
  249. <a class="toc_title" href="#objects">
  250. Objects
  251. </a>
  252. <ul class="toc_section">
  253. <li>- <a href="#keys">keys</a></li>
  254. <li>- <a href="#values">values</a></li>
  255. <li>- <a href="#pairs">pairs</a></li>
  256. <li>- <a href="#invert">invert</a></li>
  257. <li>- <a href="#object-functions">functions</a></li>
  258. <li>- <a href="#extend">extend</a></li>
  259. <li>- <a href="#pick">pick</a></li>
  260. <li>- <a href="#omit">omit</a></li>
  261. <li>- <a href="#defaults">defaults</a></li>
  262. <li>- <a href="#clone">clone</a></li>
  263. <li>- <a href="#tap">tap</a></li>
  264. <li>- <a href="#has">has</a></li>
  265. <li>- <a href="#isEqual">isEqual</a></li>
  266. <li>- <a href="#isEmpty">isEmpty</a></li>
  267. <li>- <a href="#isElement">isElement</a></li>
  268. <li>- <a href="#isArray">isArray</a></li>
  269. <li>- <a href="#isObject">isObject</a></li>
  270. <li>- <a href="#isArguments">isArguments</a></li>
  271. <li>- <a href="#isFunction">isFunction</a></li>
  272. <li>- <a href="#isString">isString</a></li>
  273. <li>- <a href="#isNumber">isNumber</a></li>
  274. <li>- <a href="#isFinite">isFinite</a></li>
  275. <li>- <a href="#isBoolean">isBoolean</a></li>
  276. <li>- <a href="#isDate">isDate</a></li>
  277. <li>- <a href="#isRegExp">isRegExp</a></li>
  278. <li>- <a href="#isNaN">isNaN</a></li>
  279. <li>- <a href="#isNull">isNull</a></li>
  280. <li>- <a href="#isUndefined">isUndefined</a></li>
  281. </ul>
  282. <a class="toc_title" href="#utility">
  283. Utility
  284. </a>
  285. <ul class="toc_section">
  286. <li>- <a href="#noConflict">noConflict</a></li>
  287. <li>- <a href="#identity">identity</a></li>
  288. <li>- <a href="#times">times</a></li>
  289. <li>- <a href="#random">random</a></li>
  290. <li>- <a href="#mixin">mixin</a></li>
  291. <li>- <a href="#uniqueId">uniqueId</a></li>
  292. <li>- <a href="#escape">escape</a></li>
  293. <li>- <a href="#unescape">unescape</a></li>
  294. <li>- <a href="#result">result</a></li>
  295. <li>- <a href="#template">template</a></li>
  296. </ul>
  297. <a class="toc_title" href="#chaining">
  298. Chaining
  299. </a>
  300. <ul class="toc_section">
  301. <li>- <a href="#chain">chain</a></li>
  302. <li>- <a href="#value">value</a></li>
  303. </ul>
  304. <a class="toc_title" href="#links">
  305. Links
  306. </a>
  307. <a class="toc_title" href="#changelog">
  308. Change Log
  309. </a>
  310. </div>
  311. <div class="container">
  312. <p id="introduction">
  313. <img id="logo" src="docs/images/underscore.png" alt="Underscore.js" />
  314. </p>
  315. <p>
  316. <a href="http://github.com/documentcloud/underscore/">Underscore</a> is a
  317. utility-belt library for JavaScript that provides a lot of the
  318. functional programming support that you would expect in
  319. <a href="http://prototypejs.org/api">Prototype.js</a>
  320. (or <a href="http://www.ruby-doc.org/core/classes/Enumerable.html">Ruby</a>),
  321. but without extending any of the built-in JavaScript objects. It's the
  322. tie to go along with <a href="http://docs.jquery.com">jQuery</a>'s tux,
  323. and <a href="http://backbonejs.org">Backbone.js</a>'s suspenders.
  324. </p>
  325. <p>
  326. Underscore provides 80-odd functions that support both the usual
  327. functional suspects: <b>map</b>, <b>select</b>, <b>invoke</b> &mdash;
  328. as well as more specialized helpers: function binding, javascript
  329. templating, deep equality testing, and so on. It delegates to built-in
  330. functions, if present, so modern browsers will use the
  331. native implementations of <b>forEach</b>, <b>map</b>, <b>reduce</b>,
  332. <b>filter</b>, <b>every</b>, <b>some</b> and <b>indexOf</b>.
  333. </p>
  334. <p>
  335. A complete <a href="test/">Test &amp; Benchmark Suite</a>
  336. is included for your perusal.
  337. </p>
  338. <p>
  339. You may also read through the <a href="docs/underscore.html">annotated source code</a>.
  340. </p>
  341. <p>
  342. The project is
  343. <a href="http://github.com/documentcloud/underscore/">hosted on GitHub</a>.
  344. You can report bugs and discuss features on the
  345. <a href="http://github.com/documentcloud/underscore/issues">issues page</a>,
  346. on Freenode in the <tt>#documentcloud</tt> channel,
  347. or send tweets to <a href="http://twitter.com/documentcloud">@documentcloud</a>.
  348. </p>
  349. <p>
  350. <i>Underscore is an open-source component of <a href="http://documentcloud.org/">DocumentCloud</a>.</i>
  351. </p>
  352. <h2>Downloads <i style="padding-left: 12px; font-size:12px;">(Right-click, and use "Save As")</i></h2>
  353. <table>
  354. <tr>
  355. <td><a href="underscore.js">Development Version (1.4.2)</a></td>
  356. <td><i>40kb, Uncompressed with Plentiful Comments</i></td>
  357. </tr>
  358. <tr>
  359. <td><a href="underscore-min.js">Production Version (1.4.2)</a></td>
  360. <td><i>4kb, Minified and Gzipped</i></td>
  361. </tr>
  362. <tr>
  363. <td colspan="2"><div class="rule"></div></td>
  364. </tr>
  365. <tr>
  366. <td><a href="https://raw.github.com/documentcloud/underscore/master/underscore.js">Edge Version</a></td>
  367. <td><i>Unreleased, current <tt>master</tt>, use at your own risk</i></td>
  368. </tr>
  369. </table>
  370. <div id="documentation">
  371. <h2 id="collections">Collection Functions (Arrays or Objects)</h2>
  372. <p id="each">
  373. <b class="header">each</b><code>_.each(list, iterator, [context])</code>
  374. <span class="alias">Alias: <b>forEach</b></span>
  375. <br />
  376. Iterates over a <b>list</b> of elements, yielding each in turn to an <b>iterator</b>
  377. function. The <b>iterator</b> is bound to the <b>context</b> object, if one is
  378. passed. Each invocation of <b>iterator</b> is called with three arguments:
  379. <tt>(element, index, list)</tt>. If <b>list</b> is a JavaScript object, <b>iterator</b>'s
  380. arguments will be <tt>(value, key, list)</tt>. Delegates to the native
  381. <b>forEach</b> function if it exists.
  382. </p>
  383. <pre>
  384. _.each([1, 2, 3], function(num){ alert(num); });
  385. =&gt; alerts each number in turn...
  386. _.each({one : 1, two : 2, three : 3}, function(num, key){ alert(num); });
  387. =&gt; alerts each number in turn...</pre>
  388. <p id="map">
  389. <b class="header">map</b><code>_.map(list, iterator, [context])</code>
  390. <span class="alias">Alias: <b>collect</b></span>
  391. <br />
  392. Produces a new array of values by mapping each value in <b>list</b>
  393. through a transformation function (<b>iterator</b>). If the native <b>map</b> method
  394. exists, it will be used instead. If <b>list</b> is a JavaScript object,
  395. <b>iterator</b>'s arguments will be <tt>(value, key, list)</tt>.
  396. </p>
  397. <pre>
  398. _.map([1, 2, 3], function(num){ return num * 3; });
  399. =&gt; [3, 6, 9]
  400. _.map({one : 1, two : 2, three : 3}, function(num, key){ return num * 3; });
  401. =&gt; [3, 6, 9]</pre>
  402. <p id="reduce">
  403. <b class="header">reduce</b><code>_.reduce(list, iterator, memo, [context])</code>
  404. <span class="alias">Aliases: <b>inject, foldl</b></span>
  405. <br />
  406. Also known as <b>inject</b> and <b>foldl</b>, <b>reduce</b> boils down a
  407. <b>list</b> of values into a single value. <b>Memo</b> is the initial state
  408. of the reduction, and each successive step of it should be returned by
  409. <b>iterator</b>. The iterator is passed four arguments: the <tt>memo</tt>,
  410. then the <tt>value</tt> and <tt>index</tt> (or key) of the iteration,
  411. and finally a reference to the entire <tt>list</tt>.
  412. </p>
  413. <pre>
  414. var sum = _.reduce([1, 2, 3], function(memo, num){ return memo + num; }, 0);
  415. =&gt; 6
  416. </pre>
  417. <p id="reduceRight">
  418. <b class="header">reduceRight</b><code>_.reduceRight(list, iterator, memo, [context])</code>
  419. <span class="alias">Alias: <b>foldr</b></span>
  420. <br />
  421. The right-associative version of <b>reduce</b>. Delegates to the
  422. JavaScript 1.8 version of <b>reduceRight</b>, if it exists. <b>Foldr</b>
  423. is not as useful in JavaScript as it would be in a language with lazy
  424. evaluation.
  425. </p>
  426. <pre>
  427. var list = [[0, 1], [2, 3], [4, 5]];
  428. var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []);
  429. =&gt; [4, 5, 2, 3, 0, 1]
  430. </pre>
  431. <p id="find">
  432. <b class="header">find</b><code>_.find(list, iterator, [context])</code>
  433. <span class="alias">Alias: <b>detect</b></span>
  434. <br />
  435. Looks through each value in the <b>list</b>, returning the first one that
  436. passes a truth test (<b>iterator</b>). The function returns as
  437. soon as it finds an acceptable element, and doesn't traverse the
  438. entire list.
  439. </p>
  440. <pre>
  441. var even = _.find([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
  442. =&gt; 2
  443. </pre>
  444. <p id="filter">
  445. <b class="header">filter</b><code>_.filter(list, iterator, [context])</code>
  446. <span class="alias">Alias: <b>select</b></span>
  447. <br />
  448. Looks through each value in the <b>list</b>, returning an array of all
  449. the values that pass a truth test (<b>iterator</b>). Delegates to the
  450. native <b>filter</b> method, if it exists.
  451. </p>
  452. <pre>
  453. var evens = _.filter([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
  454. =&gt; [2, 4, 6]
  455. </pre>
  456. <p id="where">
  457. <b class="header">where</b><code>_.where(list, properties)</code>
  458. <br />
  459. Looks through each value in the <b>list</b>, returning an array of all
  460. the values that contain all of the key-value pairs listed in <b>properties</b>.
  461. </p>
  462. <pre>
  463. _.where(listOfPlays, {author: "Shakespeare", year: 1611});
  464. =&gt; [{title: "Cymbeline", author: "Shakespeare", year: 1611},
  465. {title: "The Tempest", author: "Shakespeare", year: 1611}]
  466. </pre>
  467. <p id="reject">
  468. <b class="header">reject</b><code>_.reject(list, iterator, [context])</code>
  469. <br />
  470. Returns the values in <b>list</b> without the elements that the truth
  471. test (<b>iterator</b>) passes. The opposite of <b>filter</b>.
  472. </p>
  473. <pre>
  474. var odds = _.reject([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
  475. =&gt; [1, 3, 5]
  476. </pre>
  477. <p id="every">
  478. <b class="header">every</b><code>_.every(list, iterator, [context])</code>
  479. <span class="alias">Alias: <b>all</b></span>
  480. <br />
  481. Returns <i>true</i> if all of the values in the <b>list</b> pass the <b>iterator</b>
  482. truth test. Delegates to the native method <b>every</b>, if present.
  483. </p>
  484. <pre>
  485. _.every([true, 1, null, 'yes'], _.identity);
  486. =&gt; false
  487. </pre>
  488. <p id="some">
  489. <b class="header">some</b><code>_.some(list, [iterator], [context])</code>
  490. <span class="alias">Alias: <b>any</b></span>
  491. <br />
  492. Returns <i>true</i> if any of the values in the <b>list</b> pass the
  493. <b>iterator</b> truth test. Short-circuits and stops traversing the list
  494. if a true element is found. Delegates to the native method <b>some</b>,
  495. if present.
  496. </p>
  497. <pre>
  498. _.some([null, 0, 'yes', false]);
  499. =&gt; true
  500. </pre>
  501. <p id="contains">
  502. <b class="header">contains</b><code>_.contains(list, value)</code>
  503. <span class="alias">Alias: <b>include</b></span>
  504. <br />
  505. Returns <i>true</i> if the <b>value</b> is present in the <b>list</b>.
  506. Uses <b>indexOf</b> internally, if <b>list</b> is an Array.
  507. </p>
  508. <pre>
  509. _.contains([1, 2, 3], 3);
  510. =&gt; true
  511. </pre>
  512. <p id="invoke">
  513. <b class="header">invoke</b><code>_.invoke(list, methodName, [*arguments])</code>
  514. <br />
  515. Calls the method named by <b>methodName</b> on each value in the <b>list</b>.
  516. Any extra arguments passed to <b>invoke</b> will be forwarded on to the
  517. method invocation.
  518. </p>
  519. <pre>
  520. _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
  521. =&gt; [[1, 5, 7], [1, 2, 3]]
  522. </pre>
  523. <p id="pluck">
  524. <b class="header">pluck</b><code>_.pluck(list, propertyName)</code>
  525. <br />
  526. A convenient version of what is perhaps the most common use-case for
  527. <b>map</b>: extracting a list of property values.
  528. </p>
  529. <pre>
  530. var stooges = [{name : 'moe', age : 40}, {name : 'larry', age : 50}, {name : 'curly', age : 60}];
  531. _.pluck(stooges, 'name');
  532. =&gt; ["moe", "larry", "curly"]
  533. </pre>
  534. <p id="max">
  535. <b class="header">max</b><code>_.max(list, [iterator], [context])</code>
  536. <br />
  537. Returns the maximum value in <b>list</b>. If <b>iterator</b> is passed,
  538. it will be used on each value to generate the criterion by which the
  539. value is ranked.
  540. </p>
  541. <pre>
  542. var stooges = [{name : 'moe', age : 40}, {name : 'larry', age : 50}, {name : 'curly', age : 60}];
  543. _.max(stooges, function(stooge){ return stooge.age; });
  544. =&gt; {name : 'curly', age : 60};
  545. </pre>
  546. <p id="min">
  547. <b class="header">min</b><code>_.min(list, [iterator], [context])</code>
  548. <br />
  549. Returns the minimum value in <b>list</b>. If <b>iterator</b> is passed,
  550. it will be used on each value to generate the criterion by which the
  551. value is ranked.
  552. </p>
  553. <pre>
  554. var numbers = [10, 5, 100, 2, 1000];
  555. _.min(numbers);
  556. =&gt; 2
  557. </pre>
  558. <p id="sortBy">
  559. <b class="header">sortBy</b><code>_.sortBy(list, iterator, [context])</code>
  560. <br />
  561. Returns a sorted copy of <b>list</b>, ranked in ascending order by the
  562. results of running each value through <b>iterator</b>. Iterator may
  563. also be the string name of the property to sort by (eg. <tt>length</tt>).
  564. </p>
  565. <pre>
  566. _.sortBy([1, 2, 3, 4, 5, 6], function(num){ return Math.sin(num); });
  567. =&gt; [5, 4, 6, 3, 1, 2]
  568. </pre>
  569. <p id="groupBy">
  570. <b class="header">groupBy</b><code>_.groupBy(list, iterator)</code>
  571. <br />
  572. Splits a collection into sets, grouped by the result of running each
  573. value through <b>iterator</b>. If <b>iterator</b> is a string instead of
  574. a function, groups by the property named by <b>iterator</b> on each of
  575. the values.
  576. </p>
  577. <pre>
  578. _.groupBy([1.3, 2.1, 2.4], function(num){ return Math.floor(num); });
  579. =&gt; {1: [1.3], 2: [2.1, 2.4]}
  580. _.groupBy(['one', 'two', 'three'], 'length');
  581. =&gt; {3: ["one", "two"], 5: ["three"]}
  582. </pre>
  583. <p id="countBy">
  584. <b class="header">countBy</b><code>_.countBy(list, iterator)</code>
  585. <br />
  586. Sorts a list into groups and returns a count for the number of objects
  587. in each group.
  588. Similar to <tt>groupBy</tt>, but instead of returning a list of values,
  589. returns a count for the number of values in that group.
  590. </p>
  591. <pre>
  592. _.countBy([1, 2, 3, 4, 5], function(num) {
  593. return num % 2 == 0 ? 'even' : 'odd';
  594. });
  595. =&gt; {odd: 3, even: 2}
  596. </pre>
  597. <p id="shuffle">
  598. <b class="header">shuffle</b><code>_.shuffle(list)</code>
  599. <br />
  600. Returns a shuffled copy of the <b>list</b>, using a version of the
  601. <a href="http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle">Fisher-Yates shuffle</a>.
  602. </p>
  603. <pre>
  604. _.shuffle([1, 2, 3, 4, 5, 6]);
  605. =&gt; [4, 1, 6, 3, 5, 2]
  606. </pre>
  607. <p id="toArray">
  608. <b class="header">toArray</b><code>_.toArray(list)</code>
  609. <br />
  610. Converts the <b>list</b> (anything that can be iterated over), into a
  611. real Array. Useful for transmuting the <b>arguments</b> object.
  612. </p>
  613. <pre>
  614. (function(){ return _.toArray(arguments).slice(1); })(1, 2, 3, 4);
  615. =&gt; [2, 3, 4]
  616. </pre>
  617. <p id="size">
  618. <b class="header">size</b><code>_.size(list)</code>
  619. <br />
  620. Return the number of values in the <b>list</b>.
  621. </p>
  622. <pre>
  623. _.size({one : 1, two : 2, three : 3});
  624. =&gt; 3
  625. </pre>
  626. <h2 id="arrays">Array Functions</h2>
  627. <p>
  628. <i>
  629. Note: All array functions will also work on the <b>arguments</b> object.
  630. However, Underscore functions are not designed to work on "sparse" arrays.
  631. </i>
  632. </p>
  633. <p id="first">
  634. <b class="header">first</b><code>_.first(array, [n])</code>
  635. <span class="alias">Alias: <b>head</b>, <b>take</b></span>
  636. <br />
  637. Returns the first element of an <b>array</b>. Passing <b>n</b> will
  638. return the first <b>n</b> elements of the array.
  639. </p>
  640. <pre>
  641. _.first([5, 4, 3, 2, 1]);
  642. =&gt; 5
  643. </pre>
  644. <p id="initial">
  645. <b class="header">initial</b><code>_.initial(array, [n])</code>
  646. <br />
  647. Returns everything but the last entry of the array. Especially useful on
  648. the arguments object. Pass <b>n</b> to exclude the last <b>n</b> elements
  649. from the result.
  650. </p>
  651. <pre>
  652. _.initial([5, 4, 3, 2, 1]);
  653. =&gt; [5, 4, 3, 2]
  654. </pre>
  655. <p id="last">
  656. <b class="header">last</b><code>_.last(array, [n])</code>
  657. <br />
  658. Returns the last element of an <b>array</b>. Passing <b>n</b> will return
  659. the last <b>n</b> elements of the array.
  660. </p>
  661. <pre>
  662. _.last([5, 4, 3, 2, 1]);
  663. =&gt; 1
  664. </pre>
  665. <p id="rest">
  666. <b class="header">rest</b><code>_.rest(array, [index])</code>
  667. <span class="alias">Alias: <b>tail, drop</b></span>
  668. <br />
  669. Returns the <b>rest</b> of the elements in an array. Pass an <b>index</b>
  670. to return the values of the array from that index onward.
  671. </p>
  672. <pre>
  673. _.rest([5, 4, 3, 2, 1]);
  674. =&gt; [4, 3, 2, 1]
  675. </pre>
  676. <p id="compact">
  677. <b class="header">compact</b><code>_.compact(array)</code>
  678. <br />
  679. Returns a copy of the <b>array</b> with all falsy values removed.
  680. In JavaScript, <i>false</i>, <i>null</i>, <i>0</i>, <i>""</i>,
  681. <i>undefined</i> and <i>NaN</i> are all falsy.
  682. </p>
  683. <pre>
  684. _.compact([0, 1, false, 2, '', 3]);
  685. =&gt; [1, 2, 3]
  686. </pre>
  687. <p id="flatten">
  688. <b class="header">flatten</b><code>_.flatten(array, [shallow])</code>
  689. <br />
  690. Flattens a nested <b>array</b> (the nesting can be to any depth). If you
  691. pass <b>shallow</b>, the array will only be flattened a single level.
  692. </p>
  693. <pre>
  694. _.flatten([1, [2], [3, [[4]]]]);
  695. =&gt; [1, 2, 3, 4];
  696. _.flatten([1, [2], [3, [[4]]]], true);
  697. =&gt; [1, 2, 3, [[4]]];
  698. </pre>
  699. <p id="without">
  700. <b class="header">without</b><code>_.without(array, [*values])</code>
  701. <br />
  702. Returns a copy of the <b>array</b> with all instances of the <b>values</b>
  703. removed.
  704. </p>
  705. <pre>
  706. _.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
  707. =&gt; [2, 3, 4]
  708. </pre>
  709. <p id="union">
  710. <b class="header">union</b><code>_.union(*arrays)</code>
  711. <br />
  712. Computes the union of the passed-in <b>arrays</b>: the list of unique items,
  713. in order, that are present in one or more of the <b>arrays</b>.
  714. </p>
  715. <pre>
  716. _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]);
  717. =&gt; [1, 2, 3, 101, 10]
  718. </pre>
  719. <p id="intersection">
  720. <b class="header">intersection</b><code>_.intersection(*arrays)</code>
  721. <br />
  722. Computes the list of values that are the intersection of all the <b>arrays</b>.
  723. Each value in the result is present in each of the <b>arrays</b>.
  724. </p>
  725. <pre>
  726. _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]);
  727. =&gt; [1, 2]
  728. </pre>
  729. <p id="difference">
  730. <b class="header">difference</b><code>_.difference(array, *others)</code>
  731. <br />
  732. Similar to <b>without</b>, but returns the values from <b>array</b> that
  733. are not present in the <b>other</b> arrays.
  734. </p>
  735. <pre>
  736. _.difference([1, 2, 3, 4, 5], [5, 2, 10]);
  737. =&gt; [1, 3, 4]
  738. </pre>
  739. <p id="uniq">
  740. <b class="header">uniq</b><code>_.uniq(array, [isSorted], [iterator])</code>
  741. <span class="alias">Alias: <b>unique</b></span>
  742. <br />
  743. Produces a duplicate-free version of the <b>array</b>, using <i>===</i> to test
  744. object equality. If you know in advance that the <b>array</b> is sorted,
  745. passing <i>true</i> for <b>isSorted</b> will run a much faster algorithm.
  746. If you want to compute unique items based on a transformation, pass an
  747. <b>iterator</b> function.
  748. </p>
  749. <pre>
  750. _.uniq([1, 2, 1, 3, 1, 4]);
  751. =&gt; [1, 2, 3, 4]
  752. </pre>
  753. <p id="zip">
  754. <b class="header">zip</b><code>_.zip(*arrays)</code>
  755. <br />
  756. Merges together the values of each of the <b>arrays</b> with the
  757. values at the corresponding position. Useful when you have separate
  758. data sources that are coordinated through matching array indexes.
  759. If you're working with a matrix of nested arrays, <b>zip.apply</b>
  760. can transpose the matrix in a similar fashion.
  761. </p>
  762. <pre>
  763. _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]);
  764. =&gt; [["moe", 30, true], ["larry", 40, false], ["curly", 50, false]]
  765. </pre>
  766. <p id="object">
  767. <b class="header">object</b><code>_.object(list, [values])</code>
  768. <br />
  769. Converts arrays into objects. Pass either a single list of
  770. <tt>[key, value]</tt> pairs, or a list of keys, and a list of values.
  771. </p>
  772. <pre>
  773. _.object(['moe', 'larry', 'curly'], [30, 40, 50]);
  774. =&gt; {moe: 30, larry: 40, curly: 50}
  775. _.object([['moe', 30], ['larry', 40], ['curly', 50]]);
  776. =&gt; {moe: 30, larry: 40, curly: 50}
  777. </pre>
  778. <p id="indexOf">
  779. <b class="header">indexOf</b><code>_.indexOf(array, value, [isSorted])</code>
  780. <br />
  781. Returns the index at which <b>value</b> can be found in the <b>array</b>,
  782. or <i>-1</i> if value is not present in the <b>array</b>. Uses the native
  783. <b>indexOf</b> function unless it's missing. If you're working with a
  784. large array, and you know that the array is already sorted, pass <tt>true</tt>
  785. for <b>isSorted</b> to use a faster binary search ... or, pass a number as
  786. the third argument in order to look for the first matching value in the
  787. array after the given index.
  788. </p>
  789. <pre>
  790. _.indexOf([1, 2, 3], 2);
  791. =&gt; 1
  792. </pre>
  793. <p id="lastIndexOf">
  794. <b class="header">lastIndexOf</b><code>_.lastIndexOf(array, value, [fromIndex])</code>
  795. <br />
  796. Returns the index of the last occurrence of <b>value</b> in the <b>array</b>,
  797. or <i>-1</i> if value is not present. Uses the native <b>lastIndexOf</b>
  798. function if possible. Pass <b>fromIndex</b> to start your search at a
  799. given index.
  800. </p>
  801. <pre>
  802. _.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
  803. =&gt; 4
  804. </pre>
  805. <p id="sortedIndex">
  806. <b class="header">sortedIndex</b><code>_.sortedIndex(list, value, [iterator])</code>
  807. <br />
  808. Uses a binary search to determine the index at which the <b>value</b>
  809. <i>should</i> be inserted into the <b>list</b> in order to maintain the <b>list</b>'s
  810. sorted order. If an <b>iterator</b> is passed, it will be used to compute
  811. the sort ranking of each value, including the <b>value</b> you pass.
  812. </p>
  813. <pre>
  814. _.sortedIndex([10, 20, 30, 40, 50], 35);
  815. =&gt; 3
  816. </pre>
  817. <p id="range">
  818. <b class="header">range</b><code>_.range([start], stop, [step])</code>
  819. <br />
  820. A function to create flexibly-numbered lists of integers, handy for
  821. <tt>each</tt> and <tt>map</tt> loops. <b>start</b>, if omitted, defaults
  822. to <i>0</i>; <b>step</b> defaults to <i>1</i>. Returns a list of integers
  823. from <b>start</b> to <b>stop</b>, incremented (or decremented) by <b>step</b>,
  824. exclusive.
  825. </p>
  826. <pre>
  827. _.range(10);
  828. =&gt; [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  829. _.range(1, 11);
  830. =&gt; [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  831. _.range(0, 30, 5);
  832. =&gt; [0, 5, 10, 15, 20, 25]
  833. _.range(0, -10, -1);
  834. =&gt; [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
  835. _.range(0);
  836. =&gt; []
  837. </pre>
  838. <h2 id="functions">Function (uh, ahem) Functions</h2>
  839. <p id="bind">
  840. <b class="header">bind</b><code>_.bind(function, object, [*arguments])</code>
  841. <br />
  842. Bind a <b>function</b> to an <b>object</b>, meaning that whenever
  843. the function is called, the value of <i>this</i> will be the <b>object</b>.
  844. Optionally, bind <b>arguments</b> to the <b>function</b> to pre-fill them,
  845. also known as <b>partial application</b>.
  846. </p>
  847. <pre>
  848. var func = function(greeting){ return greeting + ': ' + this.name };
  849. func = _.bind(func, {name : 'moe'}, 'hi');
  850. func();
  851. =&gt; 'hi: moe'
  852. </pre>
  853. <p id="bindAll">
  854. <b class="header">bindAll</b><code>_.bindAll(object, [*methodNames])</code>
  855. <br />
  856. Binds a number of methods on the <b>object</b>, specified by
  857. <b>methodNames</b>, to be run in the context of that object whenever they
  858. are invoked. Very handy for binding functions that are going to be used
  859. as event handlers, which would otherwise be invoked with a fairly useless
  860. <i>this</i>. If no <b>methodNames</b> are provided, all of the object's
  861. function properties will be bound to it.
  862. </p>
  863. <pre>
  864. var buttonView = {
  865. label : 'underscore',
  866. onClick : function(){ alert('clicked: ' + this.label); },
  867. onHover : function(){ console.log('hovering: ' + this.label); }
  868. };
  869. _.bindAll(buttonView);
  870. jQuery('#underscore_button').bind('click', buttonView.onClick);
  871. =&gt; When the button is clicked, this.label will have the correct value...
  872. </pre>
  873. <p id="memoize">
  874. <b class="header">memoize</b><code>_.memoize(function, [hashFunction])</code>
  875. <br />
  876. Memoizes a given <b>function</b> by caching the computed result. Useful
  877. for speeding up slow-running computations. If passed an optional
  878. <b>hashFunction</b>, it will be used to compute the hash key for storing
  879. the result, based on the arguments to the original function. The default
  880. <b>hashFunction</b> just uses the first argument to the memoized function
  881. as the key.
  882. </p>
  883. <pre>
  884. var fibonacci = _.memoize(function(n) {
  885. return n &lt; 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
  886. });
  887. </pre>
  888. <p id="delay">
  889. <b class="header">delay</b><code>_.delay(function, wait, [*arguments])</code>
  890. <br />
  891. Much like <b>setTimeout</b>, invokes <b>function</b> after <b>wait</b>
  892. milliseconds. If you pass the optional <b>arguments</b>, they will be
  893. forwarded on to the <b>function</b> when it is invoked.
  894. </p>
  895. <pre>
  896. var log = _.bind(console.log, console);
  897. _.delay(log, 1000, 'logged later');
  898. =&gt; 'logged later' // Appears after one second.
  899. </pre>
  900. <p id="defer">
  901. <b class="header">defer</b><code>_.defer(function, [*arguments])</code>
  902. <br />
  903. Defers invoking the <b>function</b> until the current call stack has cleared,
  904. similar to using <b>setTimeout</b> with a delay of 0. Useful for performing
  905. expensive computations or HTML rendering in chunks without blocking the UI thread
  906. from updating. If you pass the optional <b>arguments</b>, they will be
  907. forwarded on to the <b>function</b> when it is invoked.
  908. </p>
  909. <pre>
  910. _.defer(function(){ alert('deferred'); });
  911. // Returns from the function before the alert runs.
  912. </pre>
  913. <p id="throttle">
  914. <b class="header">throttle</b><code>_.throttle(function, wait)</code>
  915. <br />
  916. Creates and returns a new, throttled version of the passed function,
  917. that, when invoked repeatedly, will only actually call the original function
  918. at most once per every <b>wait</b>
  919. milliseconds. Useful for rate-limiting events that occur faster than you
  920. can keep up with.
  921. </p>
  922. <pre>
  923. var throttled = _.throttle(updatePosition, 100);
  924. $(window).scroll(throttled);
  925. </pre>
  926. <p id="debounce">
  927. <b class="header">debounce</b><code>_.debounce(function, wait, [immediate])</code>
  928. <br />
  929. Creates and returns a new debounced version of the passed function that
  930. will postpone its execution until after
  931. <b>wait</b> milliseconds have elapsed since the last time it
  932. was invoked. Useful for implementing behavior that should only happen
  933. <i>after</i> the input has stopped arriving. For example: rendering a
  934. preview of a Markdown comment, recalculating a layout after the window
  935. has stopped being resized, and so on.
  936. </p>
  937. <p>
  938. Pass <tt>true</tt> for the <b>immediate</b> parameter to cause
  939. <b>debounce</b> to trigger the function on the leading instead of the
  940. trailing edge of the <b>wait</b> interval. Useful in circumstances like
  941. preventing accidental double-clicks on a "submit" button from firing a
  942. second time.
  943. </p>
  944. <pre>
  945. var lazyLayout = _.debounce(calculateLayout, 300);
  946. $(window).resize(lazyLayout);
  947. </pre>
  948. <p id="once">
  949. <b class="header">once</b><code>_.once(function)</code>
  950. <br />
  951. Creates a version of the function that can only be called one time.
  952. Repeated calls to the modified function will have no effect, returning
  953. the value from the original call. Useful for initialization functions,
  954. instead of having to set a boolean flag and then check it later.
  955. </p>
  956. <pre>
  957. var initialize = _.once(createApplication);
  958. initialize();
  959. initialize();
  960. // Application is only created once.
  961. </pre>
  962. <p id="after">
  963. <b class="header">after</b><code>_.after(count, function)</code>
  964. <br />
  965. Creates a version of the function that will only be run after first
  966. being called <b>count</b> times. Useful for grouping asynchronous responses,
  967. where you want to be sure that all the async calls have finished, before
  968. proceeding.
  969. </p>
  970. <pre>
  971. var renderNotes = _.after(notes.length, render);
  972. _.each(notes, function(note) {
  973. note.asyncSave({success: renderNotes});
  974. });
  975. // renderNotes is run once, after all notes have saved.
  976. </pre>
  977. <p id="wrap">
  978. <b class="header">wrap</b><code>_.wrap(function, wrapper)</code>
  979. <br />
  980. Wraps the first <b>function</b> inside of the <b>wrapper</b> function,
  981. passing it as the first argument. This allows the <b>wrapper</b> to
  982. execute code before and after the <b>function</b> runs, adjust the arguments,
  983. and execute it conditionally.
  984. </p>
  985. <pre>
  986. var hello = function(name) { return "hello: " + name; };
  987. hello = _.wrap(hello, function(func) {
  988. return "before, " + func("moe") + ", after";
  989. });
  990. hello();
  991. =&gt; 'before, hello: moe, after'
  992. </pre>
  993. <p id="compose">
  994. <b class="header">compose</b><code>_.compose(*functions)</code>
  995. <br />
  996. Returns the composition of a list of <b>functions</b>, where each function
  997. consumes the return value of the function that follows. In math terms,
  998. composing the functions <i>f()</i>, <i>g()</i>, and <i>h()</i> produces
  999. <i>f(g(h()))</i>.
  1000. </p>
  1001. <pre>
  1002. var greet = function(name){ return "hi: " + name; };
  1003. var exclaim = function(statement){ return statement + "!"; };
  1004. var welcome = _.compose(exclaim, greet);
  1005. welcome('moe');
  1006. =&gt; 'hi: moe!'
  1007. </pre>
  1008. <h2 id="objects">Object Functions</h2>
  1009. <p id="keys">
  1010. <b class="header">keys</b><code>_.keys(object)</code>
  1011. <br />
  1012. Retrieve all the names of the <b>object</b>'s properties.
  1013. </p>
  1014. <pre>
  1015. _.keys({one : 1, two : 2, three : 3});
  1016. =&gt; ["one", "two", "three"]
  1017. </pre>
  1018. <p id="values">
  1019. <b class="header">values</b><code>_.values(object)</code>
  1020. <br />
  1021. Return all of the values of the <b>object</b>'s properties.
  1022. </p>
  1023. <pre>
  1024. _.values({one : 1, two : 2, three : 3});
  1025. =&gt; [1, 2, 3]
  1026. </pre>
  1027. <p id="pairs">
  1028. <b class="header">pairs</b><code>_.pairs(object)</code>
  1029. <br />
  1030. Convert an object into a list of <tt>[key, value]</tt> pairs.
  1031. </p>
  1032. <pre>
  1033. _.pairs({one: 1, two: 2, three: 3});
  1034. =&gt; [["one", 1], ["two", 2], ["three", 3]]
  1035. </pre>
  1036. <p id="invert">
  1037. <b class="header">invert</b><code>_.invert(object)</code>
  1038. <br />
  1039. Returns a copy of the <b>object</b> where the keys have become the values
  1040. and the values the keys. For this to work, all of your object's values
  1041. should be unique and string serializable.
  1042. </p>
  1043. <pre>
  1044. _.invert({Moe: "Moses", Larry: "Louis", Curly: "Jerome"});
  1045. =&gt; {Moses: "Moe", Louis: "Larry", Jerome: "Curly"};
  1046. </pre>
  1047. <p id="object-functions">
  1048. <b class="header">functions</b><code>_.functions(object)</code>
  1049. <span class="alias">Alias: <b>methods</b></span>
  1050. <br />
  1051. Returns a sorted list of the names of every method in an object &mdash;
  1052. that is to say, the name of every function property of the object.
  1053. </p>
  1054. <pre>
  1055. _.functions(_);
  1056. =&gt; ["all", "any", "bind", "bindAll", "clone", "compact", "compose" ...
  1057. </pre>
  1058. <p id="extend">
  1059. <b class="header">extend</b><code>_.extend(destination, *sources)</code>
  1060. <br />
  1061. Copy all of the properties in the <b>source</b> objects over to the
  1062. <b>destination</b> object, and return the <b>destination</b> object.
  1063. It's in-order, so the last source will override properties of the same
  1064. name in previous arguments.
  1065. </p>
  1066. <pre>
  1067. _.extend({name : 'moe'}, {age : 50});
  1068. =&gt; {name : 'moe', age : 50}
  1069. </pre>
  1070. <p id="pick">
  1071. <b class="header">pick</b><code>_.pick(object, *keys)</code>
  1072. <br />
  1073. Return a copy of the <b>object</b>, filtered to only have values for
  1074. the whitelisted <b>keys</b> (or array of valid keys).
  1075. </p>
  1076. <pre>
  1077. _.pick({name : 'moe', age: 50, userid : 'moe1'}, 'name', 'age');
  1078. =&gt; {name : 'moe', age : 50}
  1079. </pre>
  1080. <p id="omit">
  1081. <b class="header">omit</b><code>_.omit(object, *keys)</code>
  1082. <br />
  1083. Return a copy of the <b>object</b>, filtered to omit the blacklisted
  1084. <b>keys</b> (or array of keys).
  1085. </p>
  1086. <pre>
  1087. _.omit({name : 'moe', age : 50, userid : 'moe1'}, 'userid');
  1088. =&gt; {name : 'moe', age : 50}
  1089. </pre>
  1090. <p id="defaults">
  1091. <b class="header">defaults</b><code>_.defaults(object, *defaults)</code>
  1092. <br />
  1093. Fill in null and undefined properties in <b>object</b> with values from the
  1094. <b>defaults</b> objects, and return the <b>object</b>. As soon as the
  1095. property is filled, further defaults will have no effect.
  1096. </p>
  1097. <pre>
  1098. var iceCream = {flavor : "chocolate"};
  1099. _.defaults(iceCream, {flavor : "vanilla", sprinkles : "lots"});
  1100. =&gt; {flavor : "chocolate", sprinkles : "lots"}
  1101. </pre>
  1102. <p id="clone">
  1103. <b class="header">clone</b><code>_.clone(object)</code>
  1104. <br />
  1105. Create a shallow-copied clone of the <b>object</b>. Any nested objects
  1106. or arrays will be copied by reference, not duplicated.
  1107. </p>
  1108. <pre>
  1109. _.clone({name : 'moe'});
  1110. =&gt; {name : 'moe'};
  1111. </pre>
  1112. <p id="tap">
  1113. <b class="header">tap</b><code>_.tap(object, interceptor)</code>
  1114. <br />
  1115. Invokes <b>interceptor</b> with the <b>object</b>, and then returns <b>object</b>.
  1116. The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
  1117. </p>
  1118. <pre>
  1119. _.chain([1,2,3,200])
  1120. .filter(function(num) { return num % 2 == 0; })
  1121. .tap(alert)
  1122. .map(function(num) { return num * num })
  1123. .value();
  1124. =&gt; // [2, 200] (alerted)
  1125. =&gt; [4, 40000]
  1126. </pre>
  1127. <p id="has">
  1128. <b class="header">has</b><code>_.has(object, key)</code>
  1129. <br />
  1130. Does the object contain the given key? Identical to
  1131. <tt>object.hasOwnProperty(key)</tt>, but uses a safe reference to the
  1132. <tt>hasOwnProperty</tt> function, in case it's been
  1133. <a href="http://www.devthought.com/2012/01/18/an-object-is-not-a-hash/">overridden accidentally</a>.
  1134. </p>
  1135. <pre>
  1136. _.has({a: 1, b: 2, c: 3}, "b");
  1137. =&gt; true
  1138. </pre>
  1139. <p id="isEqual">
  1140. <b class="header">isEqual</b><code>_.isEqual(object, other)</code>
  1141. <br />
  1142. Performs an optimized deep comparison between the two objects, to determine
  1143. if they should be considered equal.
  1144. </p>
  1145. <pre>
  1146. var moe = {name : 'moe', luckyNumbers : [13, 27, 34]};
  1147. var clone = {name : 'moe', luckyNumbers : [13, 27, 34]};
  1148. moe == clone;
  1149. =&gt; false
  1150. _.isEqual(moe, clone);
  1151. =&gt; true
  1152. </pre>
  1153. <p id="isEmpty">
  1154. <b class="header">isEmpty</b><code>_.isEmpty(object)</code>
  1155. <br />
  1156. Returns <i>true</i> if <b>object</b> contains no values.
  1157. </p>
  1158. <pre>
  1159. _.isEmpty([1, 2, 3]);
  1160. =&gt; false
  1161. _.isEmpty({});
  1162. =&gt; true
  1163. </pre>
  1164. <p id="isElement">
  1165. <b class="header">isElement</b><code>_.isElement(object)</code>
  1166. <br />
  1167. Returns <i>true</i> if <b>object</b> is a DOM element.
  1168. </p>
  1169. <pre>
  1170. _.isElement(jQuery('body')[0]);
  1171. =&gt; true
  1172. </pre>
  1173. <p id="isArray">
  1174. <b class="header">isArray</b><code>_.isArray(object)</code>
  1175. <br />
  1176. Returns <i>true</i> if <b>object</b> is an Array.
  1177. </p>
  1178. <pre>
  1179. (function(){ return _.isArray(arguments); })();
  1180. =&gt; false
  1181. _.isArray([1,2,3]);
  1182. =&gt; true
  1183. </pre>
  1184. <p id="isObject">
  1185. <b class="header">isObject</b><code>_.isObject(value)</code>
  1186. <br />
  1187. Returns <i>true</i> if <b>value</b> is an Object. Note that JavaScript
  1188. arrays and functions are objects, while (normal) strings and numbers are not.
  1189. </p>
  1190. <pre>
  1191. _.isObject({});
  1192. =&gt; true
  1193. _.isObject(1);
  1194. =&gt; false
  1195. </pre>
  1196. <p id="isArguments">
  1197. <b class="header">isArguments</b><code>_.isArguments(object)</code>
  1198. <br />
  1199. Returns <i>true</i> if <b>object</b> is an Arguments object.
  1200. </p>
  1201. <pre>
  1202. (function(){ return _.isArguments(arguments); })(1, 2, 3);
  1203. =&gt; true
  1204. _.isArguments([1,2,3]);
  1205. =&gt; false
  1206. </pre>
  1207. <p id="isFunction">
  1208. <b class="header">isFunction</b><code>_.isFunction(object)</code>
  1209. <br />
  1210. Returns <i>true</i> if <b>object</b> is a Function.
  1211. </p>
  1212. <pre>
  1213. _.isFunction(alert);
  1214. =&gt; true
  1215. </pre>
  1216. <p id="isString">
  1217. <b class="header">isString</b><code>_.isString(object)</code>
  1218. <br />
  1219. Returns <i>true</i> if <b>object</b> is a String.
  1220. </p>
  1221. <pre>
  1222. _.isString("moe");
  1223. =&gt; true
  1224. </pre>
  1225. <p id="isNumber">
  1226. <b class="header">isNumber</b><code>_.isNumber(object)</code>
  1227. <br />
  1228. Returns <i>true</i> if <b>object</b> is a Number (including <tt>NaN</tt>).
  1229. </p>
  1230. <pre>
  1231. _.isNumber(8.4 * 5);
  1232. =&gt; true
  1233. </pre>
  1234. <p id="isFinite">
  1235. <b class="header">isFinite</b><code>_.isFinite(object)</code>
  1236. <br />
  1237. Returns <i>true</i> if <b>object</b> is a finite Number.
  1238. </p>
  1239. <pre>
  1240. _.isFinite(-101);
  1241. =&gt; true
  1242. _.isFinite(-Infinity);
  1243. =&gt; false
  1244. </pre>
  1245. <p id="isBoolean">
  1246. <b class="header">isBoolean</b><code>_.isBoolean(object)</code>
  1247. <br />
  1248. Returns <i>true</i> if <b>object</b> is either <i>true</i> or <i>false</i>.
  1249. </p>
  1250. <pre>
  1251. _.isBoolean(null);
  1252. =&gt; false
  1253. </pre>
  1254. <p id="isDate">
  1255. <b class="header">isDate</b><code>_.isDate(object)</code>
  1256. <br />
  1257. Returns <i>true</i> if <b>object</b> is a Date.
  1258. </p>
  1259. <pre>
  1260. _.isDate(new Date());
  1261. =&gt; true
  1262. </pre>
  1263. <p id="isRegExp">
  1264. <b class="header">isRegExp</b><code>_.isRegExp(object)</code>
  1265. <br />
  1266. Returns <i>true</i> if <b>object</b> is a RegExp.
  1267. </p>
  1268. <pre>
  1269. _.isRegExp(/moe/);
  1270. =&gt; true
  1271. </pre>
  1272. <p id="isNaN">
  1273. <b class="header">isNaN</b><code>_.isNaN(object)</code>
  1274. <br />
  1275. Returns <i>true</i> if <b>object</b> is <i>NaN</i>.<br /> Note: this is not
  1276. the same as the native <b>isNaN</b> function, which will also return
  1277. true if the variable is <i>undefined</i>.
  1278. </p>
  1279. <pre>
  1280. _.isNaN(NaN);
  1281. =&gt; true
  1282. isNaN(undefined);
  1283. =&gt; true
  1284. _.isNaN(undefined);
  1285. =&gt; false
  1286. </pre>
  1287. <p id="isNull">
  1288. <b class="header">isNull</b><code>_.isNull(object)</code>
  1289. <br />
  1290. Returns <i>true</i> if the value of <b>object</b> is <i>null</i>.
  1291. </p>
  1292. <pre>
  1293. _.isNull(null);
  1294. =&gt; true
  1295. _.isNull(undefined);
  1296. =&gt; false
  1297. </pre>
  1298. <p id="isUndefined">
  1299. <b class="header">isUndefined</b><code>_.isUndefined(value)</code>
  1300. <br />
  1301. Returns <i>true</i> if <b>value</b> is <i>undefined</i>.
  1302. </p>
  1303. <pre>
  1304. _.isUndefined(window.missingVariable);
  1305. =&gt; true
  1306. </pre>
  1307. <h2 id="utility">Utility Functions</h2>
  1308. <p id="noConflict">
  1309. <b class="header">noConflict</b><code>_.noConflict()</code>
  1310. <br />
  1311. Give control of the "_" variable back to its previous owner. Returns
  1312. a reference to the <b>Underscore</b> object.
  1313. </p>
  1314. <pre>
  1315. var underscore = _.noConflict();</pre>
  1316. <p id="identity">
  1317. <b class="header">identity</b><code>_.identity(value)</code>
  1318. <br />
  1319. Returns the same value that is used as the argument. In math:
  1320. <tt>f(x) = x</tt><br />
  1321. This function looks useless, but is used throughout Underscore as
  1322. a default iterator.
  1323. </p>
  1324. <pre>
  1325. var moe = {name : 'moe'};
  1326. moe === _.identity(moe);
  1327. =&gt; true</pre>
  1328. <p id="times">
  1329. <b class="header">times</b><code>_.times(n, iterator, [context])</code>
  1330. <br />
  1331. Invokes the given iterator function <b>n</b> times. Each invocation of
  1332. <b>iterator</b> is called with an <tt>index</tt> argument.
  1333. <br />
  1334. <i>Note: this example uses the <a href="#chaining">chaining syntax</a></i>.
  1335. </p>
  1336. <pre>
  1337. _(3).times(function(n){ genie.grantWishNumber(n); });</pre>
  1338. <p id="random">
  1339. <b class="header">random</b><code>_.random(min, max)</code>
  1340. <br />
  1341. Returns a random integer between <b>min</b> and <b>max</b>, inclusive.
  1342. If you only pass one argument, it will return a number between <tt>0</tt>
  1343. and that number.
  1344. </p>
  1345. <pre>
  1346. _.random(0, 100);
  1347. =&gt; 42</pre>
  1348. <p id="mixin">
  1349. <b class="header">mixin</b><code>_.mixin(object)</code>
  1350. <br />
  1351. Allows you to extend Underscore with your own utility functions. Pass
  1352. a hash of <tt>{name: function}</tt> definitions to have your functions
  1353. added to the Underscore object, as well as the OOP wrapper.
  1354. </p>
  1355. <pre>
  1356. _.mixin({
  1357. capitalize : function(string) {
  1358. return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase();
  1359. }
  1360. });
  1361. _("fabio").capitalize();
  1362. =&gt; "Fabio"
  1363. </pre>
  1364. <p id="uniqueId">
  1365. <b class="header">uniqueId</b><code>_.uniqueId([prefix])</code>
  1366. <br />
  1367. Generate a globally-unique id for client-side models or DOM elements
  1368. that need one. If <b>prefix</b> is passed, the id will be appended to it.
  1369. Without <b>prefix</b>, returns an integer.
  1370. </p>
  1371. <pre>
  1372. _.uniqueId('contact_');
  1373. =&gt; 'contact_104'</pre>
  1374. <p id="escape">
  1375. <b class="header">escape</b><code>_.escape(string)</code>
  1376. <br />
  1377. Escapes a string for insertion into HTML, replacing
  1378. <tt>&amp;</tt>, <tt>&lt;</tt>, <tt>&gt;</tt>, <tt>&quot;</tt>, <tt>&#x27;</tt>, and <tt>&#x2F;</tt> characters.
  1379. </p>
  1380. <pre>
  1381. _.escape('Curly, Larry &amp; Moe');
  1382. =&gt; "Curly, Larry &amp;amp; Moe"</pre>
  1383. <p id="unescape">
  1384. <b class="header">unescape</b><code>_.unescape(string)</code>
  1385. <br />
  1386. The opposite of <a href="#escape"><b>escape</b></a>, replaces
  1387. <tt>&amp;amp;</tt>, <tt>&amp;lt;</tt>, <tt>&amp;gt;</tt>,
  1388. <tt>&amp;quot;</tt>, <tt>&amp;#x27;</tt>, and <tt>&amp;#x2F;</tt>
  1389. with their unescaped counterparts.
  1390. </p>
  1391. <pre>
  1392. _.escape('Curly, Larry &amp;amp; Moe');
  1393. =&gt; "Curly, Larry &amp; Moe"</pre>
  1394. <p id="result">
  1395. <b class="header">result</b><code>_.result(object, property)</code>
  1396. <br />
  1397. If the value of the named property is a function then invoke it; otherwise, return it.
  1398. </p>
  1399. <pre>
  1400. var object = {cheese: 'crumpets', stuff: function(){ return 'nonsense'; }};
  1401. _.result(object, 'cheese');
  1402. =&gt; "crumpets"
  1403. _.result(object, 'stuff');
  1404. =&gt; "nonsense"</pre>
  1405. <p id="template">
  1406. <b class="header">template</b><code>_.template(templateString, [data], [settings])</code>
  1407. <br />
  1408. Compiles JavaScript templates into functions that can be evaluated
  1409. for rendering. Useful for rendering complicated bits of HTML from JSON
  1410. data sources. Template functions can both interpolate variables, using
  1411. <tt>&lt;%= &hellip; %&gt;</tt>, as well as execute arbitrary JavaScript code, with
  1412. <tt>&lt;% &hellip; %&gt;</tt>. If you wish to interpolate a value, and have
  1413. it be HTML-escaped, use <tt>&lt;%- &hellip; %&gt;</tt> When you evaluate a template function, pass in a
  1414. <b>data</b> object that has properties corresponding to the template's free
  1415. variables. If you're writing a one-off, you can pass the <b>data</b>
  1416. object as the second parameter to <b>template</b> in order to render
  1417. immediately instead of returning a template function. The <b>settings</b> argument
  1418. should be a hash containing any <tt>_.templateSettings</tt> that should be overridden.
  1419. </p>
  1420. <pre>
  1421. var compiled = _.template("hello: &lt;%= name %&gt;");
  1422. compiled({name : 'moe'});
  1423. =&gt; "hello: moe"
  1424. var list = "&lt;% _.each(people, function(name) { %&gt; &lt;li&gt;&lt;%= name %&gt;&lt;/li&gt; &lt;% }); %&gt;";
  1425. _.template(list, {people : ['moe', 'curly', 'larry']});
  1426. =&gt; "&lt;li&gt;moe&lt;/li&gt;&lt;li&gt;curly&lt;/li&gt;&lt;li&gt;larry&lt;/li&gt;"
  1427. var template = _.template("&lt;b&gt;&lt;%- value %&gt;&lt;/b&gt;");
  1428. template({value : '&lt;script&gt;'});
  1429. =&gt; "&lt;b&gt;&amp;lt;script&amp;gt;&lt;/b&gt;"</pre>
  1430. <p>
  1431. You can also use <tt>print</tt> from within JavaScript code. This is
  1432. sometimes more convenient than using <tt>&lt;%= ... %&gt;</tt>.
  1433. </p>
  1434. <pre>
  1435. var compiled = _.template("&lt;% print('Hello ' + epithet); %&gt;");
  1436. compiled({epithet: "stooge"});
  1437. =&gt; "Hello stooge."</pre>
  1438. <p>
  1439. If ERB-style delimiters aren't your cup of tea, you can change Underscore's
  1440. template settings to use different symbols to set off interpolated code.
  1441. Define an <b>interpolate</b> regex to match expressions that should be
  1442. interpolated verbatim, an <b>escape</b> regex to match expressions that should
  1443. be inserted after being HTML escaped, and an <b>evaluate</b> regex to match
  1444. expressions that should be evaluated without insertion into the resulting
  1445. string. You may define or omit any combination of the three.
  1446. For example, to perform
  1447. <a href="http://github.com/janl/mustache.js#readme">Mustache.js</a>
  1448. style templating:
  1449. </p>
  1450. <pre>
  1451. _.templateSettings = {
  1452. interpolate : /\{\{(.+?)\}\}/g
  1453. };
  1454. var template = _.template("Hello {{ name }}!");
  1455. template({name : "Mustache"});
  1456. =&gt; "Hello Mustache!"</pre>
  1457. <p>
  1458. By default, <b>template</b> places the values from your data in the local scope
  1459. via the <tt>with</tt> statement. However, you can specify a single variable name
  1460. with the <b>variable</b> setting. This can significantly improve the speed
  1461. at which a template is able to render.
  1462. </p>
  1463. <pre>
  1464. _.template("Using 'with': <%= data.answer %>", {answer: 'no'}, {variable: 'data'});
  1465. =&gt; "Using 'with': no"</pre>
  1466. <p>
  1467. Precompiling your templates can be a big help when debugging errors you can't
  1468. reproduce. This is because precompiled templates can provide line numbers and
  1469. a stack trace, something that is not possible when compiling templates on the client.
  1470. The <b>source</b> property is available on the compiled template
  1471. function for easy precompilation.
  1472. </p>
  1473. <pre>&lt;script&gt;
  1474. JST.project = <%= _.template(jstText).source %>;
  1475. &lt;/script&gt;</pre>
  1476. <h2 id="chaining">Chaining</h2>
  1477. <p>
  1478. You can use Underscore in either an object-oriented or a functional style,
  1479. depending on your preference. The following two lines of code are
  1480. identical ways to double a list of numbers.
  1481. </p>
  1482. <pre>
  1483. _.map([1, 2, 3], function(n){ return n * 2; });
  1484. _([1, 2, 3]).map(function(n){ return n * 2; });</pre>
  1485. <p>
  1486. Calling <tt>chain</tt> will cause all future method calls to return
  1487. wrapped objects. When you've finished the computation, use
  1488. <tt>value</tt> to retrieve the final value. Here's an example of chaining
  1489. together a <b>map/flatten/reduce</b>, in order to get the word count of
  1490. every word in a song.
  1491. </p>
  1492. <pre>
  1493. var lyrics = [
  1494. {line : 1, words : "I'm a lumberjack and I'm okay"},
  1495. {line : 2, words : "I sleep all night and I work all day"},
  1496. {line : 3, words : "He's a lumberjack and he's okay"},
  1497. {line : 4, words : "He sleeps all night and he works all day"}
  1498. ];
  1499. _.chain(lyrics)
  1500. .map(function(line) { return line.words.split(' '); })
  1501. .flatten()
  1502. .reduce(function(counts, word) {
  1503. counts[word] = (counts[word] || 0) + 1;
  1504. return counts;
  1505. }, {}).value();
  1506. =&gt; {lumberjack : 2, all : 4, night : 2 ... }</pre>
  1507. <p>
  1508. In addition, the
  1509. <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/prototype">Array prototype's methods</a>
  1510. are proxied through the chained Underscore object, so you can slip a
  1511. <tt>reverse</tt> or a <tt>push</tt> into your chain, and continue to
  1512. modify the array.
  1513. </p>
  1514. <p id="chain">
  1515. <b class="header">chain</b><code>_.chain(obj)</code>
  1516. <br />
  1517. Returns a wrapped object. Calling methods on this object will continue
  1518. to return wrapped objects until <tt>value</tt> is used.
  1519. </p>
  1520. <pre>
  1521. var stooges = [{name : 'curly', age : 25}, {name : 'moe', age : 21}, {name : 'larry', age : 23}];
  1522. var youngest = _.chain(stooges)
  1523. .sortBy(function(stooge){ return stooge.age; })
  1524. .map(function(stooge){ return stooge.name + ' is ' + stooge.age; })
  1525. .first()
  1526. .value();
  1527. =&gt; "moe is 21"
  1528. </pre>
  1529. <p id="value">
  1530. <b class="header">value</b><code>_(obj).value()</code>
  1531. <br />
  1532. Extracts the value of a wrapped object.
  1533. </p>
  1534. <pre>
  1535. _([1, 2, 3]).value();
  1536. =&gt; [1, 2, 3]
  1537. </pre>
  1538. <h2 id="links">Links &amp; Suggested Reading</h2>
  1539. <p>
  1540. The Underscore documentation is also available in
  1541. <a href="http://learning.github.com/underscore/">Simplified Chinese</a>.
  1542. </p>
  1543. <p>
  1544. <a href="http://mirven.github.com/underscore.lua/">Underscore.lua</a>,
  1545. a Lua port of the functions that are applicable in both languages.
  1546. Includes OOP-wrapping and chaining.
  1547. (<a href="http://github.com/mirven/underscore.lua">source</a>)
  1548. </p>
  1549. <p>
  1550. <a href="http://underscorem.org">Underscore.m</a>, an Objective-C port
  1551. of many of the Underscore.js functions, using a syntax that encourages
  1552. chaining.
  1553. (<a href="https://github.com/robb/Underscore.m">source</a>)
  1554. </p>
  1555. <p>
  1556. <a href="http://kmalakoff.github.com/_.m/">_.m</a>, an alternative
  1557. Objective-C port that tries to stick a little closer to the original
  1558. Underscore.js API.
  1559. (<a href="https://github.com/kmalakoff/_.m">source</a>)
  1560. </p>
  1561. <p>
  1562. <a href="http://brianhaveri.github.com/Underscore.php/">Underscore.php</a>,
  1563. a PHP port of the functions that are applicable in both languages.
  1564. Includes OOP-wrapping and chaining.
  1565. (<a href="http://github.com/brianhaveri/Underscore.php">source</a>)
  1566. </p>
  1567. <p>
  1568. <a href="http://vti.github.com/underscore-perl/">Underscore-perl</a>,
  1569. a Perl port of many of the Underscore.js functions,
  1570. aimed at on Perl hashes and arrays.
  1571. (<a href="https://github.com/vti/underscore-perl/">source</a>)
  1572. </p>
  1573. <p>
  1574. <a href="http://russplaysguitar.github.com/UnderscoreCF/">Underscore.cfc</a>,
  1575. a Coldfusion port of many of the Underscore.js functions.
  1576. (<a href="https://github.com/russplaysguitar/underscorecf">source</a>)
  1577. </p>
  1578. <p>
  1579. <a href="https://github.com/edtsech/underscore.string">Underscore.string</a>,
  1580. an Underscore extension that adds functions for string-manipulation:
  1581. <tt>trim</tt>, <tt>startsWith</tt>, <tt>contains</tt>, <tt>capitalize</tt>,
  1582. <tt>reverse</tt>, <tt>sprintf</tt>, and more.
  1583. </p>
  1584. <p>
  1585. Ruby's <a href="http://ruby-doc.org/core/classes/Enumerable.html">Enumerable</a> module.
  1586. </p>
  1587. <p>
  1588. <a href="http://www.prototypejs.org/">Prototype.js</a>, which provides
  1589. JavaScript with collection functions in the manner closest to Ruby's Enumerable.
  1590. </p>
  1591. <p>
  1592. Oliver Steele's
  1593. <a href="http://osteele.com/sources/javascript/functional/">Functional JavaScript</a>,
  1594. which includes comprehensive higher-order function support as well as string lambdas.
  1595. </p>
  1596. <p>
  1597. Michael Aufreiter's <a href="http://github.com/michael/data">Data.js</a>,
  1598. a data manipulation + persistence library for JavaScript.
  1599. </p>
  1600. <p>
  1601. Python's <a href="http://docs.python.org/library/itertools.html">itertools</a>.
  1602. </p>
  1603. <h2 id="changelog">Change Log</h2>
  1604. <p>
  1605. <b class="header">1.4.2</b> &mdash; <small><i>Oct. 1, 2012</i></small> &mdash; <a href="https://github.com/documentcloud/underscore/compare/1.4.1...1.4.2">Diff</a><br />
  1606. <ul>
  1607. <li>
  1608. For backwards compatibility, returned to pre-1.4.0 behavior when
  1609. passing <tt>null</tt> to iteration functions. They now become no-ops
  1610. again.
  1611. </li>
  1612. </ul>
  1613. </p>
  1614. <p>
  1615. <b class="header">1.4.1</b> &mdash; <small><i>Oct. 1, 2012</i></small> &mdash; <a href="https://github.com/documentcloud/underscore/compare/1.4.0...1.4.1">Diff</a><br />
  1616. <ul>
  1617. <li>
  1618. Fixed a 1.4.0 regression in the <tt>lastIndexOf</tt> function.
  1619. </li>
  1620. </ul>
  1621. </p>
  1622. <p>
  1623. <b class="header">1.4.0</b> &mdash; <small><i>Sept. 27, 2012</i></small> &mdash; <a href="https://github.com/documentcloud/underscore/compare/1.3.3...1.4.0">Diff</a><br />
  1624. <ul>
  1625. <li>
  1626. Added a <tt>pairs</tt> function, for turning a JavaScript object
  1627. into <tt>[key, value]</tt> pairs ... as well as an <tt>object</tt>
  1628. function, for converting an array of <tt>[key, value]</tt> pairs
  1629. into an object.
  1630. </li>
  1631. <li>
  1632. Added a <tt>countBy</tt> function, for counting the number of objects
  1633. in a list that match a certain criteria.
  1634. </li>
  1635. <li>
  1636. Added an <tt>invert</tt> function, for performing a simple inversion
  1637. of the keys and values in an object.
  1638. </li>
  1639. <li>
  1640. Added a <tt>where</tt> function, for easy cases of filtering a list
  1641. for objects with specific values.
  1642. </li>
  1643. <li>
  1644. Added an <tt>omit</tt> function, for filtering an object to remove
  1645. certain keys.
  1646. </li>
  1647. <li>
  1648. Added a <tt>random</tt> function, to return a random number in a
  1649. given range.
  1650. </li>
  1651. <li>
  1652. <tt>_.debounce</tt>'d functions now return their last updated value,
  1653. just like <tt>_.throttle</tt>'d functions do.
  1654. </li>
  1655. <li>
  1656. The <tt>sortBy</tt> function now runs a stable sort algorithm.
  1657. </li>
  1658. <li>
  1659. Added the optional <tt>fromIndex</tt> option to <tt>indexOf</tt> and
  1660. <tt>lastIndexOf</tt>.
  1661. </li>
  1662. <li>
  1663. "Sparse" arrays are no longer supported in Underscore iteration
  1664. functions. Use a <tt>for</tt> loop instead (or better yet, an object).
  1665. </li>
  1666. <li>
  1667. The <tt>min</tt> and <tt>max</tt> functions may now be called on
  1668. <i>very</i> large arrays.
  1669. </li>
  1670. <li>
  1671. Interpolation in templates now represents <tt>null</tt> and
  1672. <tt>undefined</tt> as the empty string.
  1673. </li>
  1674. <li>
  1675. <del>Underscore iteration functions no longer accept <tt>null</tt> values
  1676. as a no-op argument. You'll get an early error instead.</del>
  1677. </li>
  1678. <li>
  1679. A number of edge-cases fixes and tweaks, which you can spot in the
  1680. <a href="https://github.com/documentcloud/underscore/compare/1.3.3...1.4.0">diff</a>.
  1681. Depending on how you're using Underscore, <b>1.4.0</b> may be more
  1682. backwards-incompatible than usual &mdash; please test when you upgrade.
  1683. </li>
  1684. </ul>
  1685. </p>
  1686. <p>
  1687. <b class="header">1.3.3</b> &mdash; <small><i>April 10, 2012</i></small><br />
  1688. <ul>
  1689. <li>
  1690. Many improvements to <tt>_.template</tt>, which now provides the
  1691. <tt>source</tt> of the template function as a property, for potentially
  1692. even more efficient pre-compilation on the server-side. You may now
  1693. also set the <tt>variable</tt> option when creating a template,
  1694. which will cause your passed-in data to be made available under the
  1695. variable you named, instead of using a <tt>with</tt> statement &mdash;
  1696. significantly improving the speed of rendering the template.
  1697. </li>
  1698. <li>
  1699. Added the <tt>pick</tt> function, which allows you to filter an
  1700. object literal with a whitelist of allowed property names.
  1701. </li>
  1702. <li>
  1703. Added the <tt>result</tt> function, for convenience when working
  1704. with APIs that allow either functions or raw properties.
  1705. </li>
  1706. <li>
  1707. Added the <tt>isFinite</tt> function, because sometimes knowing that
  1708. a value is a number just ain't quite enough.
  1709. </li>
  1710. <li>
  1711. The <tt>sortBy</tt> function may now also be passed the string name
  1712. of a property to use as the sort order on each object.
  1713. </li>
  1714. <li>
  1715. Fixed <tt>uniq</tt> to work with sparse arrays.
  1716. </li>
  1717. <li>
  1718. The <tt>difference</tt> function now performs a shallow flatten
  1719. instead of a deep one when computing array differences.
  1720. </li>
  1721. <li>
  1722. The <tt>debounce</tt> function now takes an <tt>immediate</tt>
  1723. parameter, which will cause the callback to fire on the leading
  1724. instead of the trailing edge.
  1725. </li>
  1726. </ul>
  1727. </p>
  1728. <p>
  1729. <b class="header">1.3.1</b> &mdash; <small><i>Jan. 23, 2012</i></small><br />
  1730. <ul>
  1731. <li>
  1732. Added an <tt>_.has</tt> function, as a safer way to use <tt>hasOwnProperty</tt>.
  1733. </li>
  1734. <li>
  1735. Added <tt>_.collect</tt> as an alias for <tt>_.map</tt>. Smalltalkers, rejoice.
  1736. </li>
  1737. <li>
  1738. Reverted an old change so that <tt>_.extend</tt> will correctly copy
  1739. over keys with undefined values again.
  1740. </li>
  1741. <li>
  1742. Bugfix to stop escaping slashes within interpolations in <tt>_.template</tt>.
  1743. </li>
  1744. </ul>
  1745. </p>
  1746. <p>
  1747. <b class="header">1.3.0</b> &mdash; <small><i>Jan. 11, 2012</i></small><br />
  1748. <ul>
  1749. <li>
  1750. Removed AMD (RequireJS) support from Underscore. If you'd like to use
  1751. Underscore with RequireJS, you can load it as a normal script, wrap
  1752. or patch your copy, or download a forked version.
  1753. </li>
  1754. </ul>
  1755. </p>
  1756. <p>
  1757. <b class="header">1.2.4</b> &mdash; <small><i>Jan. 4, 2012</i></small><br />
  1758. <ul>
  1759. <li>
  1760. You now can (and probably should, as it's simpler)
  1761. write <tt>_.chain(list)</tt>
  1762. instead of <tt>_(list).chain()</tt>.
  1763. </li>
  1764. <li>
  1765. Fix for escaped characters in Underscore templates, and for supporting
  1766. customizations of <tt>_.templateSettings</tt> that only define one or
  1767. two of the required regexes.
  1768. </li>
  1769. <li>
  1770. Fix for passing an array as the first argument to an <tt>_.wrap</tt>'d function.
  1771. </li>
  1772. <li>
  1773. Improved compatibility with ClojureScript, which adds a <tt>call</tt>
  1774. function to <tt>String.prototype</tt>.
  1775. </li>
  1776. </ul>
  1777. </p>
  1778. <p>
  1779. <b class="header">1.2.3</b> &mdash; <small><i>Dec. 7, 2011</i></small><br />
  1780. <ul>
  1781. <li>
  1782. Dynamic scope is now preserved for compiled <tt>_.template</tt> functions,
  1783. so you can use the value of <tt>this</tt> if you like.
  1784. </li>
  1785. <li>
  1786. Sparse array support of <tt>_.indexOf</tt>, <tt>_.lastIndexOf</tt>.
  1787. </li>
  1788. <li>
  1789. Both <tt>_.reduce</tt> and <tt>_.reduceRight</tt> can now be passed an
  1790. explicitly <tt>undefined</tt> value. (There's no reason why you'd
  1791. want to do this.)
  1792. </li>
  1793. </ul>
  1794. </p>
  1795. <p>
  1796. <b class="header">1.2.2</b> &mdash; <small><i>Nov. 14, 2011</i></small><br />
  1797. <ul>
  1798. <li>
  1799. Continued tweaks to <tt>_.isEqual</tt> semantics. Now JS primitives are
  1800. considered equivalent to their wrapped versions, and arrays are compared
  1801. by their numeric properties only <small>(#351)</small>.
  1802. </li>
  1803. <li>
  1804. <tt>_.escape</tt> no longer tries to be smart about not double-escaping
  1805. already-escaped HTML entities. Now it just escapes regardless <small>(#350)</small>.
  1806. </li>
  1807. <li>
  1808. In <tt>_.template</tt>, you may now leave semicolons out of evaluated
  1809. statements if you wish: <tt>&lt;% }) %&gt;</tt> <small>(#369)</small>.
  1810. </li>
  1811. <li>
  1812. <tt>_.after(callback, 0)</tt> will now trigger the callback immediately,
  1813. making "after" easier to use with asynchronous APIs <small>(#366)</small>.
  1814. </li>
  1815. </ul>
  1816. </p>
  1817. <p>
  1818. <b class="header">1.2.1</b> &mdash; <small><i>Oct. 24, 2011</i></small><br />
  1819. <ul>
  1820. <li>
  1821. Several important bug fixes for <tt>_.isEqual</tt>, which should now
  1822. do better on mutated Arrays, and on non-Array objects with
  1823. <tt>length</tt> properties. <small>(#329)</small>
  1824. </li>
  1825. <li>
  1826. <b>jrburke</b> contributed Underscore exporting for AMD module loaders,
  1827. and <b>tonylukasavage</b> for Appcelerator Titanium.
  1828. <small>(#335, #338)</small>
  1829. </li>
  1830. <li>
  1831. You can now <tt>_.groupBy(list, 'property')</tt> as a shortcut for
  1832. grouping values by a particular common property.
  1833. </li>
  1834. <li>
  1835. <tt>_.throttle</tt>'d functions now fire immediately upon invocation,
  1836. and are rate-limited thereafter <small>(#170, #266)</small>.
  1837. </li>
  1838. <li>
  1839. Most of the <tt>_.is[Type]</tt> checks no longer ducktype.
  1840. </li>
  1841. <li>
  1842. The <tt>_.bind</tt> function now also works on constructors, a-la
  1843. ES5 ... but you would never want to use <tt>_.bind</tt> on a
  1844. constructor function.
  1845. </li>
  1846. <li>
  1847. <tt>_.clone</tt> no longer wraps non-object types in Objects.
  1848. </li>
  1849. <li>
  1850. <tt>_.find</tt> and <tt>_.filter</tt> are now the preferred names for
  1851. <tt>_.detect</tt> and <tt>_.select</tt>.
  1852. </li>
  1853. </ul>
  1854. </p>
  1855. <p>
  1856. <b class="header">1.2.0</b> &mdash; <small><i>Oct. 5, 2011</i></small><br />
  1857. <ul>
  1858. <li>
  1859. The <tt>_.isEqual</tt> function now
  1860. supports true deep equality comparisons, with checks for cyclic structures,
  1861. thanks to Kit Cambridge.
  1862. </li>
  1863. <li>
  1864. Underscore templates now support HTML escaping interpolations, using
  1865. <tt>&lt;%- ... %&gt;</tt> syntax.
  1866. </li>
  1867. <li>
  1868. Ryan Tenney contributed <tt>_.shuffle</tt>, which uses a modified
  1869. Fisher-Yates to give you a shuffled copy of an array.
  1870. </li>
  1871. <li>
  1872. <tt>_.uniq</tt> can now be passed an optional iterator, to determine by
  1873. what criteria an object should be considered unique.
  1874. </li>
  1875. <li>
  1876. <tt>_.last</tt> now takes an optional argument which will return the last
  1877. N elements of the list.
  1878. </li>
  1879. <li>
  1880. A new <tt>_.initial</tt> function was added, as a mirror of <tt>_.rest</tt>,
  1881. which returns all the initial values of a list (except the last N).
  1882. </li>
  1883. </ul>
  1884. </p>
  1885. <p>
  1886. <b class="header">1.1.7</b> &mdash; <small><i>July 13, 2011</i></small><br />
  1887. Added <tt>_.groupBy</tt>, which aggregates a collection into groups of like items.
  1888. Added <tt>_.union</tt> and <tt>_.difference</tt>, to complement the
  1889. (re-named) <tt>_.intersection</tt>.
  1890. Various improvements for support of sparse arrays.
  1891. <tt>_.toArray</tt> now returns a clone, if directly passed an array.
  1892. <tt>_.functions</tt> now also returns the names of functions that are present
  1893. in the prototype chain.
  1894. </p>
  1895. <p>
  1896. <b class="header">1.1.6</b> &mdash; <small><i>April 18, 2011</i></small><br />
  1897. Added <tt>_.after</tt>, which will return a function that only runs after
  1898. first being called a specified number of times.
  1899. <tt>_.invoke</tt> can now take a direct function reference.
  1900. <tt>_.every</tt> now requires an iterator function to be passed, which
  1901. mirrors the ECMA5 API.
  1902. <tt>_.extend</tt> no longer copies keys when the value is undefined.
  1903. <tt>_.bind</tt> now errors when trying to bind an undefined value.
  1904. </p>
  1905. <p>
  1906. <b class="header">1.1.5</b> &mdash; <small><i>Mar 20, 2011</i></small><br />
  1907. Added an <tt>_.defaults</tt> function, for use merging together JS objects
  1908. representing default options.
  1909. Added an <tt>_.once</tt> function, for manufacturing functions that should
  1910. only ever execute a single time.
  1911. <tt>_.bind</tt> now delegates to the native ECMAScript 5 version,
  1912. where available.
  1913. <tt>_.keys</tt> now throws an error when used on non-Object values, as in
  1914. ECMAScript 5.
  1915. Fixed a bug with <tt>_.keys</tt> when used over sparse arrays.
  1916. </p>
  1917. <p>
  1918. <b class="header">1.1.4</b> &mdash; <small><i>Jan 9, 2011</i></small><br />
  1919. Improved compliance with ES5's Array methods when passing <tt>null</tt>
  1920. as a value. <tt>_.wrap</tt> now correctly sets <tt>this</tt> for the
  1921. wrapped function. <tt>_.indexOf</tt> now takes an optional flag for
  1922. finding the insertion index in an array that is guaranteed to already
  1923. be sorted. Avoiding the use of <tt>.callee</tt>, to allow <tt>_.isArray</tt>
  1924. to work properly in ES5's strict mode.
  1925. </p>
  1926. <p>
  1927. <b class="header">1.1.3</b> &mdash; <small><i>Dec 1, 2010</i></small><br />
  1928. In CommonJS, Underscore may now be required with just: <br />
  1929. <tt>var _ = require("underscore")</tt>.
  1930. Added <tt>_.throttle</tt> and <tt>_.debounce</tt> functions.
  1931. Removed <tt>_.breakLoop</tt>, in favor of an ECMA5-style un-<i>break</i>-able
  1932. each implementation &mdash; this removes the try/catch, and you'll now have
  1933. better stack traces for exceptions that are thrown within an Underscore iterator.
  1934. Improved the <b>isType</b> family of functions for better interoperability
  1935. with Internet Explorer host objects.
  1936. <tt>_.template</tt> now correctly escapes backslashes in templates.
  1937. Improved <tt>_.reduce</tt> compatibility with the ECMA5 version:
  1938. if you don't pass an initial value, the first item in the collection is used.
  1939. <tt>_.each</tt> no longer returns the iterated collection, for improved
  1940. consistency with ES5's <tt>forEach</tt>.
  1941. </p>
  1942. <p>
  1943. <b class="header">1.1.2</b><br />
  1944. Fixed <tt>_.contains</tt>, which was mistakenly pointing at
  1945. <tt>_.intersect</tt> instead of <tt>_.include</tt>, like it should
  1946. have been. Added <tt>_.unique</tt> as an alias for <tt>_.uniq</tt>.
  1947. </p>
  1948. <p>
  1949. <b class="header">1.1.1</b><br />
  1950. Improved the speed of <tt>_.template</tt>, and its handling of multiline
  1951. interpolations. Ryan Tenney contributed optimizations to many Underscore
  1952. functions. An annotated version of the source code is now available.
  1953. </p>
  1954. <p>
  1955. <b class="header">1.1.0</b><br />
  1956. The method signature of <tt>_.reduce</tt> has been changed to match
  1957. the ECMAScript 5 signature, instead of the Ruby/Prototype.js version.
  1958. This is a backwards-incompatible change. <tt>_.template</tt> may now be
  1959. called with no arguments, and preserves whitespace. <tt>_.contains</tt>
  1960. is a new alias for <tt>_.include</tt>.
  1961. </p>
  1962. <p>
  1963. <b class="header">1.0.4</b><br />
  1964. <a href="http://themoell.com/">Andri Möll</a> contributed the <tt>_.memoize</tt>
  1965. function, which can be used to speed up expensive repeated computations
  1966. by caching the results.
  1967. </p>
  1968. <p>
  1969. <b class="header">1.0.3</b><br />
  1970. Patch that makes <tt>_.isEqual</tt> return <tt>false</tt> if any property
  1971. of the compared object has a <tt>NaN</tt> value. Technically the correct
  1972. thing to do, but of questionable semantics. Watch out for NaN comparisons.
  1973. </p>
  1974. <p>
  1975. <b class="header">1.0.2</b><br />
  1976. Fixes <tt>_.isArguments</tt> in recent versions of Opera, which have
  1977. arguments objects as real Arrays.
  1978. </p>
  1979. <p>
  1980. <b class="header">1.0.1</b><br />
  1981. Bugfix for <tt>_.isEqual</tt>, when comparing two objects with the same
  1982. number of undefined keys, but with different names.
  1983. </p>
  1984. <p>
  1985. <b class="header">1.0.0</b><br />
  1986. Things have been stable for many months now, so Underscore is now
  1987. considered to be out of beta, at <b>1.0</b>. Improvements since <b>0.6</b>
  1988. include <tt>_.isBoolean</tt>, and the ability to have <tt>_.extend</tt>
  1989. take multiple source objects.
  1990. </p>
  1991. <p>
  1992. <b class="header">0.6.0</b><br />
  1993. Major release. Incorporates a number of
  1994. <a href="http://github.com/ratbeard">Mile Frawley's</a> refactors for
  1995. safer duck-typing on collection functions, and cleaner internals. A new
  1996. <tt>_.mixin</tt> method that allows you to extend Underscore with utility
  1997. functions of your own. Added <tt>_.times</tt>, which works the same as in
  1998. Ruby or Prototype.js. Native support for ECMAScript 5's <tt>Array.isArray</tt>,
  1999. and <tt>Object.keys</tt>.
  2000. </p>
  2001. <p>
  2002. <b class="header">0.5.8</b><br />
  2003. Fixed Underscore's collection functions to work on
  2004. <a href="https://developer.mozilla.org/En/DOM/NodeList">NodeLists</a> and
  2005. <a href="https://developer.mozilla.org/En/DOM/HTMLCollection">HTMLCollections</a>
  2006. once more, thanks to
  2007. <a href="http://github.com/jmtulloss">Justin Tulloss</a>.
  2008. </p>
  2009. <p>
  2010. <b class="header">0.5.7</b><br />
  2011. A safer implementation of <tt>_.isArguments</tt>, and a
  2012. faster <tt>_.isNumber</tt>,<br />thanks to
  2013. <a href="http://jedschmidt.com/">Jed Schmidt</a>.
  2014. </p>
  2015. <p>
  2016. <b class="header">0.5.6</b><br />
  2017. Customizable delimiters for <tt>_.template</tt>, contributed by
  2018. <a href="http://github.com/iamnoah">Noah Sloan</a>.
  2019. </p>
  2020. <p>
  2021. <b class="header">0.5.5</b><br />
  2022. Fix for a bug in MobileSafari's OOP-wrapper, with the arguments object.
  2023. </p>
  2024. <p>
  2025. <b class="header">0.5.4</b><br />
  2026. Fix for multiple single quotes within a template string for
  2027. <tt>_.template</tt>. See:
  2028. <a href="http://www.west-wind.com/Weblog/posts/509108.aspx">Rick Strahl's blog post</a>.
  2029. </p>
  2030. <p>
  2031. <b class="header">0.5.2</b><br />
  2032. New implementations of <tt>isArray</tt>, <tt>isDate</tt>, <tt>isFunction</tt>,
  2033. <tt>isNumber</tt>, <tt>isRegExp</tt>, and <tt>isString</tt>, thanks to
  2034. a suggestion from
  2035. <a href="http://www.broofa.com/">Robert Kieffer</a>.
  2036. Instead of doing <tt>Object#toString</tt>
  2037. comparisons, they now check for expected properties, which is less safe,
  2038. but more than an order of magnitude faster. Most other Underscore
  2039. functions saw minor speed improvements as a result.
  2040. <a href="http://dolzhenko.org/">Evgeniy Dolzhenko</a>
  2041. contributed <tt>_.tap</tt>,
  2042. <a href="http://ruby-doc.org/core-1.9/classes/Object.html#M000191">similar to Ruby 1.9's</a>,
  2043. which is handy for injecting side effects (like logging) into chained calls.
  2044. </p>
  2045. <p>
  2046. <b class="header">0.5.1</b><br />
  2047. Added an <tt>_.isArguments</tt> function. Lots of little safety checks
  2048. and optimizations contributed by
  2049. <a href="http://github.com/iamnoah/">Noah Sloan</a> and
  2050. <a href="http://themoell.com/">Andri Möll</a>.
  2051. </p>
  2052. <p>
  2053. <b class="header">0.5.0</b><br />
  2054. <b>[API Changes]</b> <tt>_.bindAll</tt> now takes the context object as
  2055. its first parameter. If no method names are passed, all of the context
  2056. object's methods are bound to it, enabling chaining and easier binding.
  2057. <tt>_.functions</tt> now takes a single argument and returns the names
  2058. of its Function properties. Calling <tt>_.functions(_)</tt> will get you
  2059. the previous behavior.
  2060. Added <tt>_.isRegExp</tt> so that <tt>isEqual</tt> can now test for RegExp equality.
  2061. All of the "is" functions have been shrunk down into a single definition.
  2062. <a href="http://github.com/grayrest/">Karl Guertin</a> contributed patches.
  2063. </p>
  2064. <p>
  2065. <b class="header">0.4.7</b><br />
  2066. Added <tt>isDate</tt>, <tt>isNaN</tt>, and <tt>isNull</tt>, for completeness.
  2067. Optimizations for <tt>isEqual</tt> when checking equality between Arrays
  2068. or Dates. <tt>_.keys</tt> is now <small><i><b>25%&ndash;2X</b></i></small> faster (depending on your
  2069. browser) which speeds up the functions that rely on it, such as <tt>_.each</tt>.
  2070. </p>
  2071. <p>
  2072. <b class="header">0.4.6</b><br />
  2073. Added the <tt>range</tt> function, a port of the
  2074. <a href="http://docs.python.org/library/functions.html#range">Python
  2075. function of the same name</a>, for generating flexibly-numbered lists
  2076. of integers. Original patch contributed by
  2077. <a href="http://github.com/kylichuku">Kirill Ishanov</a>.
  2078. </p>
  2079. <p>
  2080. <b class="header">0.4.5</b><br />
  2081. Added <tt>rest</tt> for Arrays and arguments objects, and aliased
  2082. <tt>first</tt> as <tt>head</tt>, and <tt>rest</tt> as <tt>tail</tt>,
  2083. thanks to <a href="http://github.com/lukesutton/">Luke Sutton</a>'s patches.
  2084. Added tests ensuring that all Underscore Array functions also work on
  2085. <i>arguments</i> objects.
  2086. </p>
  2087. <p>
  2088. <b class="header">0.4.4</b><br />
  2089. Added <tt>isString</tt>, and <tt>isNumber</tt>, for consistency. Fixed
  2090. <tt>_.isEqual(NaN, NaN)</tt> to return <i>true</i> (which is debatable).
  2091. </p>
  2092. <p>
  2093. <b class="header">0.4.3</b><br />
  2094. Started using the native <tt>StopIteration</tt> object in browsers that support it.
  2095. Fixed Underscore setup for CommonJS environments.
  2096. </p>
  2097. <p>
  2098. <b class="header">0.4.2</b><br />
  2099. Renamed the unwrapping function to <tt>value</tt>, for clarity.
  2100. </p>
  2101. <p>
  2102. <b class="header">0.4.1</b><br />
  2103. Chained Underscore objects now support the Array prototype methods, so
  2104. that you can perform the full range of operations on a wrapped array
  2105. without having to break your chain. Added a <tt>breakLoop</tt> method
  2106. to <b>break</b> in the middle of any Underscore iteration. Added an
  2107. <tt>isEmpty</tt> function that works on arrays and objects.
  2108. </p>
  2109. <p>
  2110. <b class="header">0.4.0</b><br />
  2111. All Underscore functions can now be called in an object-oriented style,
  2112. like so: <tt>_([1, 2, 3]).map(...);</tt>. Original patch provided by
  2113. <a href="http://macournoyer.com/">Marc-André Cournoyer</a>.
  2114. Wrapped objects can be chained through multiple
  2115. method invocations. A <a href="#object-functions"><tt>functions</tt></a> method
  2116. was added, providing a sorted list of all the functions in Underscore.
  2117. </p>
  2118. <p>
  2119. <b class="header">0.3.3</b><br />
  2120. Added the JavaScript 1.8 function <tt>reduceRight</tt>. Aliased it
  2121. as <tt>foldr</tt>, and aliased <tt>reduce</tt> as <tt>foldl</tt>.
  2122. </p>
  2123. <p>
  2124. <b class="header">0.3.2</b><br />
  2125. Now runs on stock <a href="http://www.mozilla.org/rhino/">Rhino</a>
  2126. interpreters with: <tt>load("underscore.js")</tt>.
  2127. Added <a href="#identity"><tt>identity</tt></a> as a utility function.
  2128. </p>
  2129. <p>
  2130. <b class="header">0.3.1</b><br />
  2131. All iterators are now passed in the original collection as their third
  2132. argument, the same as JavaScript 1.6's <b>forEach</b>. Iterating over
  2133. objects is now called with <tt>(value, key, collection)</tt>, for details
  2134. see <a href="#each"><tt>_.each</tt></a>.
  2135. </p>
  2136. <p>
  2137. <b class="header">0.3.0</b><br />
  2138. Added <a href="http://github.com/dmitryBaranovskiy">Dmitry Baranovskiy</a>'s
  2139. comprehensive optimizations, merged in
  2140. <a href="http://github.com/kriskowal/">Kris Kowal</a>'s patches to make Underscore
  2141. <a href="http://wiki.commonjs.org/wiki/CommonJS">CommonJS</a> and
  2142. <a href="http://narwhaljs.org/">Narwhal</a> compliant.
  2143. </p>
  2144. <p>
  2145. <b class="header">0.2.0</b><br />
  2146. Added <tt>compose</tt> and <tt>lastIndexOf</tt>, renamed <tt>inject</tt> to
  2147. <tt>reduce</tt>, added aliases for <tt>inject</tt>, <tt>filter</tt>,
  2148. <tt>every</tt>, <tt>some</tt>, and <tt>forEach</tt>.
  2149. </p>
  2150. <p>
  2151. <b class="header">0.1.1</b><br />
  2152. Added <tt>noConflict</tt>, so that the "Underscore" object can be assigned to
  2153. other variables.
  2154. </p>
  2155. <p>
  2156. <b class="header">0.1.0</b><br />
  2157. Initial release of Underscore.js.
  2158. </p>
  2159. <p>
  2160. <a href="http://documentcloud.org/" title="A DocumentCloud Project" style="background:none;">
  2161. <img src="http://jashkenas.s3.amazonaws.com/images/a_documentcloud_project.png" alt="A DocumentCloud Project" />
  2162. </a>
  2163. </p>
  2164. </div>
  2165. </div>
  2166. <!-- Include Underscore, so you can play with it in the console. -->
  2167. <script type="text/javascript" src="underscore.js"></script>
  2168. </body>
  2169. </html>