Underscore.js 1.1.3

This commit is contained in:
Jeremy Ashkenas
2010-12-01 12:49:45 -05:00
parent 2d06e1d526
commit c714175cf1
6 changed files with 211 additions and 155 deletions

View File

@@ -105,7 +105,7 @@
The project is
<a href="http://github.com/documentcloud/underscore/">hosted on GitHub</a>.
You can report bugs and discuss features on the
<a href="http://github.com/documentcloud/jammit/issues">issues page</a>,
<a href="http://github.com/documentcloud/underscore/issues">issues page</a>,
on Freenode in the <tt>#documentcloud</tt> channel,
or send tweets to <a href="http://twitter.com/documentcloud">@documentcloud</a>.
</p>
@@ -118,11 +118,11 @@
<table>
<tr>
<td><a href="underscore.js">Development Version (1.1.2)</a></td>
<td><i>25kb, Uncompressed with Comments</i></td>
<td><a href="underscore.js">Development Version (1.1.3)</a></td>
<td><i>26kb, Uncompressed with Comments</i></td>
</tr>
<tr>
<td><a href="underscore-min.js">Production Version (1.1.2)</a></td>
<td><a href="underscore-min.js">Production Version (1.1.3)</a></td>
<td><i>3kb, Packed and Gzipped</i></td>
</tr>
</table>
@@ -159,6 +159,7 @@
<br />
<span class="methods"><a href="#bind">bind</a>, <a href="#bindAll">bindAll</a>,
<a href="#memoize">memoize</a>, <a href="#delay">delay</a>, <a href="#defer">defer</a>,
<a href="#throttle">throttle</a>, <a href="#debounce">debounce</a>,
<a href="#wrap">wrap</a>, <a href="#compose">compose</a></span>
</p>
@@ -180,8 +181,8 @@
<br />
<span class="methods"><a href="#noConflict">noConflict</a>,
<a href="#identity">identity</a>, <a href="#times">times</a>,
<a href="#breakLoop">breakLoop</a>, <a href="#mixin">mixin</a>,
<a href="#uniqueId">uniqueId</a>, <a href="#template">template</a></span>
<a href="#mixin">mixin</a>, <a href="#uniqueId">uniqueId</a>,
<a href="#template">template</a></span>
</p>
<p>
@@ -249,8 +250,7 @@ _(lyrics).chain()
function. The <b>iterator</b> is bound to the <b>context</b> object, if one is
passed. Each invocation of <b>iterator</b> is called with three arguments:
<tt>(element, index, list)</tt>. If <b>list</b> is a JavaScript object, <b>iterator</b>'s
arguments will be <tt>(value, key, list)</tt>. Use <a href="#breakLoop"><tt>breakLoop</tt></a>
to break out of the iteration. Delegates to the native
arguments will be <tt>(value, key, list)</tt>. Delegates to the native
<b>forEach</b> function if it exists.
</p>
<pre>
@@ -707,6 +707,33 @@ _.delay(log, 1000, 'logged later');
<pre>
_.defer(function(){ alert('deferred'); });
// Returns from the function before the alert runs.
</pre>
<p id="throttle">
<b class="header">throttle</b><code>_.throttle(function, wait)</code>
<br />
Returns a throttled version of the function, that, when invoked repeatedly,
will only actually call the wrapped function at most once per every <b>wait</b>
milliseconds. Useful for rate-limiting events that occur faster than you
can keep up with.
</p>
<pre>
var throttled = _.throttle(updatePosition, 100);
$(window).scroll(throttled);
</pre>
<p id="debounce">
<b class="header">debounce</b><code>_.debounce(function, wait)</code>
<br />
Repeated calls to a debounced function will postpone it's execution
until after <b>wait</b> milliseconds have elapsed. Useful for implementing
behavior that should only happen <i>after</i> the input has stopped arriving.
For example: rendering a preview of a Markdown comment, recalculating a
layout after the window has stopped being resized...
</p>
<pre>
var lazyLayout _.debounce(calculateLayout, 300);
$(window).resize(lazyLayout);
</pre>
<p id="wrap">
@@ -1006,22 +1033,6 @@ moe === _.identity(moe);
<pre>
_(3).times(function(){ genie.grantWish(); });</pre>
<p id="breakLoop">
<b class="header">breakLoop</b><code>_.breakLoop()</code>
<br />
Breaks out of the current loop iteration. Similar to the <tt>break</tt>
keyword in regular "for" loop, but works within an iterator function.
Uses the native <tt>StopIteration</tt> object in JavaScript 1.7 compliant
browsers.
</p>
<pre>
var result = null;
_.each([1, 2, 3], function(num) {
if ((result = num) == 2) _.breakLoop();
});
result;
=&gt; 2</pre>
<p id="mixin">
<b class="header">mixin</b><code>_.mixin(object)</code>
<br />
@@ -1170,6 +1181,21 @@ _([1, 2, 3]).value();
<h2>Change Log</h2>
<p>
<b class="header">1.1.3</b> &mdash; <small><i>Dec 1, 2010</i></small><br />
In CommonJS, Underscore may now be required with just: <br />
<tt>var _ = require("underscore")</tt>.
Added <tt>_.throttle</tt> and <tt>_.debounce</tt> functions.
Removed <tt>_.breakLoop</tt>, in favor of an ECMA5-style un-<i>break</i>-able
each implementation &mdash; this removes the try/catch, and you'll now have
better stack traces for exceptions that are thrown within an Underscore iterator.
Improved the <b>isType</b> family of functions for better interoperability
with Internet Explorer host objects.
<tt>_.template</tt> now correctly escapes backslashes in templates.
Improved <tt>_.reduce</tt> compatibility with the ECMA5 version:
if you don't pass an initial value, the first item in the collection is used.
</p>
<p>
<b class="header">1.1.2</b><br />
Fixed <tt>_.contains</tt>, which was mistakenly pointing at