mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 01:57:50 +00:00
Fixing broken link, adding explanation of _.map's iterator's arguments, and adding extra examples to _.map and _.each.
This commit is contained in:
15
index.html
15
index.html
@@ -225,7 +225,7 @@ _(lyrics).chain()
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
In addition, the
|
In addition, the
|
||||||
<a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/Array">Array prototype's methods</a>
|
<a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/prototype">Array prototype's methods</a>
|
||||||
are proxied through the chained Underscore object, so you can slip a
|
are proxied through the chained Underscore object, so you can slip a
|
||||||
<tt>reverse</tt> or a <tt>push</tt> into your chain, and continue to
|
<tt>reverse</tt> or a <tt>push</tt> into your chain, and continue to
|
||||||
modify the array.
|
modify the array.
|
||||||
@@ -247,17 +247,22 @@ _(lyrics).chain()
|
|||||||
</p>
|
</p>
|
||||||
<pre>
|
<pre>
|
||||||
_.each([1, 2, 3], function(num){ alert(num); });
|
_.each([1, 2, 3], function(num){ alert(num); });
|
||||||
|
=> alerts each number in turn...
|
||||||
|
_.each({one : 1, two : 2, three : 3}, function(num, key){ alert(num); });
|
||||||
=> alerts each number in turn...</pre>
|
=> alerts each number in turn...</pre>
|
||||||
|
|
||||||
<p id="map">
|
<p id="map">
|
||||||
<b class="header">map</b><code>_.map(list, iterator, [context])</code>
|
<b class="header">map</b><code>_.map(list, iterator, [context])</code>
|
||||||
<br />
|
<br />
|
||||||
Produces a new array of values by mapping each value in <b>list</b>
|
Produces a new array of values by mapping each value in <b>list</b>
|
||||||
through a transformation function (<b>iterator</b>). If the native
|
through a transformation function (<b>iterator</b>). If the native <b>map</b> method
|
||||||
<b>map</b> method exists, it will be used instead.
|
exists, it will be used instead. If <b>list</b> is a JavaScript object,
|
||||||
|
<b>iterator</b>'s arguments will be <tt>(value, key, list)</tt>.
|
||||||
</p>
|
</p>
|
||||||
<pre>
|
<pre>
|
||||||
_.map([1, 2, 3], function(num){ return num * 3 });
|
_.map([1, 2, 3], function(num){ return num * 3; });
|
||||||
|
=> [3, 6, 9]
|
||||||
|
_.map({one : 1, two : 2, three : 3}, function(num, key){ return num * 3; });
|
||||||
=> [3, 6, 9]</pre>
|
=> [3, 6, 9]</pre>
|
||||||
|
|
||||||
<p id="reduce">
|
<p id="reduce">
|
||||||
@@ -270,7 +275,7 @@ _.map([1, 2, 3], function(num){ return num * 3 });
|
|||||||
<b>iterator</b>.
|
<b>iterator</b>.
|
||||||
</p>
|
</p>
|
||||||
<pre>
|
<pre>
|
||||||
var sum = _.reduce([1, 2, 3], function(memo, num){ return memo + num }, 0);
|
var sum = _.reduce([1, 2, 3], function(memo, num){ return memo + num; }, 0);
|
||||||
=> 6
|
=> 6
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user