mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
version 0.4.2 -- quick patch to rename get() to value() for clarity, and adding jQuery comparisons in the speed tests
This commit is contained in:
25
index.html
25
index.html
@@ -107,11 +107,11 @@
|
||||
<p>
|
||||
<table>
|
||||
<tr>
|
||||
<td><a href="underscore.js">Development Version (0.4.1)</a></td>
|
||||
<td><a href="underscore.js">Development Version (0.4.2)</a></td>
|
||||
<td><i>18kb, Uncompressed with Comments</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="underscore-min.js">Production Version (0.4.1)</a></td>
|
||||
<td><a href="underscore-min.js">Production Version (0.4.2)</a></td>
|
||||
<td><i>2kb, Packed and Gzipped</i></td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -133,7 +133,7 @@ _([1, 2, 3]).map(function(n){ return n * 2; });</pre>
|
||||
Using the object-oriented style allows you to chain together methods. Calling
|
||||
<tt>chain</tt> on a wrapped object will cause all future method calls to
|
||||
return wrapped objects as well. When you've finished the computation,
|
||||
use <tt>get</tt> to retrieve the final value. Here's an example of chaining
|
||||
use <tt>value</tt> to retrieve the final value. Here's an example of chaining
|
||||
together a <b>map/flatten/reduce</b>, in order to get the word count of
|
||||
every word in a song.
|
||||
</p>
|
||||
@@ -152,7 +152,7 @@ _(lyrics).chain()
|
||||
.reduce({}, function(counts, word) {
|
||||
counts[word] = (counts[word] || 0) + 1;
|
||||
return counts;
|
||||
}).get();
|
||||
}).value();
|
||||
|
||||
=> {lumberjack : 2, all : 4, night : 2 ... }</pre>
|
||||
|
||||
@@ -217,7 +217,7 @@ _(lyrics).chain()
|
||||
<p>
|
||||
<b>Chaining</b>
|
||||
<br />
|
||||
<span class="methods"><a href="#chain">chain</a>, <a href="#get">get</a>
|
||||
<span class="methods"><a href="#chain">chain</a>, <a href="#value">value</a>
|
||||
</p>
|
||||
|
||||
<div id="documentation">
|
||||
@@ -864,7 +864,7 @@ _.template(list, {people : ['moe', 'curly', 'larry']});
|
||||
<b class="header">chain</b><code>_(obj).chain()</code>
|
||||
<br />
|
||||
Returns a wrapped object. Calling methods on this object will continue
|
||||
to return wrapped objects until <tt>get</tt> is used. (
|
||||
to return wrapped objects until <tt>value</tt> is used. (
|
||||
<a href="#styles">A more realistic example.</a>)
|
||||
</p>
|
||||
<pre>
|
||||
@@ -873,22 +873,27 @@ var youngest = _(stooges).chain()
|
||||
.sortBy(function(stooge){ return stooge.age; })
|
||||
.map(function(stooge){ return stooge.name + ' is ' + stooge.age; })
|
||||
.first()
|
||||
.get();
|
||||
.value();
|
||||
=> "moe is 21"
|
||||
</pre>
|
||||
|
||||
<p id="get">
|
||||
<b class="header">get</b><code>_(obj).get()</code>
|
||||
<p id="value">
|
||||
<b class="header">value</b><code>_(obj).value()</code>
|
||||
<br />
|
||||
Extracts the value of a wrapped object.
|
||||
</p>
|
||||
<pre>
|
||||
_([1, 2, 3]).get();
|
||||
_([1, 2, 3]).value();
|
||||
=> [1, 2, 3]
|
||||
</pre>
|
||||
|
||||
<h2>Change Log</h2>
|
||||
|
||||
<p>
|
||||
<b class="header">0.4.2</b><br />
|
||||
Renamed the unwrapping function to <tt>value</tt>, for clarity.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b class="header">0.4.1</b><br />
|
||||
Chained Underscore objects now support the Array prototype methods, so
|
||||
|
||||
@@ -16,7 +16,7 @@ $(document).ready(function() {
|
||||
hash[l] = hash[l] || 0;
|
||||
hash[l]++;
|
||||
return hash;
|
||||
}).get();
|
||||
}).value();
|
||||
ok(counts['a'] == 16 && counts['e'] == 10, 'counted all the letters in the song');
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@ $(document).ready(function() {
|
||||
return n % 4 == 0;
|
||||
}).sortBy(function(n) {
|
||||
return -n;
|
||||
}).get();
|
||||
}).value();
|
||||
equals(numbers.join(', '), "10, 6, 2", "filtered and reversed the numbers");
|
||||
});
|
||||
|
||||
@@ -40,7 +40,7 @@ $(document).ready(function() {
|
||||
.unshift(17)
|
||||
.pop()
|
||||
.map(function(n){ return n * 2; })
|
||||
.get();
|
||||
.value();
|
||||
equals(numbers.join(', '), "34, 10, 8, 6, 4, 2, 10, 10", 'can chain together array functions.');
|
||||
});
|
||||
|
||||
|
||||
@@ -1,54 +1,64 @@
|
||||
(function() {
|
||||
|
||||
|
||||
var numbers = [];
|
||||
for (var i=0; i<1000; i++) numbers.push(i);
|
||||
var objects = _.map(numbers, function(n){ return {num : n}; });
|
||||
var randomized = _.sortBy(numbers, function(){ return Math.random(); });
|
||||
|
||||
|
||||
JSLitmus.test('_.each()', function() {
|
||||
var timesTwo = [];
|
||||
_.each(numbers, function(num){ timesTwo.push(num * 2); });
|
||||
return timesTwo;
|
||||
});
|
||||
|
||||
|
||||
JSLitmus.test('_(list).each()', function() {
|
||||
var timesTwo = [];
|
||||
_(numbers).each(function(num){ timesTwo.push(num * 2); });
|
||||
return timesTwo;
|
||||
});
|
||||
|
||||
|
||||
JSLitmus.test('jQuery.each()', function() {
|
||||
var timesTwo = [];
|
||||
jQuery.each(numbers, function(){ timesTwo.push(this * 2); });
|
||||
return timesTwo;
|
||||
});
|
||||
|
||||
JSLitmus.test('_.map()', function() {
|
||||
return _.map(objects, function(obj){ return obj.num; });
|
||||
});
|
||||
|
||||
|
||||
JSLitmus.test('jQuery.map()', function() {
|
||||
return jQuery.map(objects, function(obj){ return obj.num; });
|
||||
});
|
||||
|
||||
JSLitmus.test('_.pluck()', function() {
|
||||
return _.pluck(objects, 'num');
|
||||
});
|
||||
|
||||
|
||||
JSLitmus.test('_.uniq()', function() {
|
||||
return _.uniq(randomized);
|
||||
});
|
||||
|
||||
|
||||
JSLitmus.test('_.uniq() (sorted)', function() {
|
||||
return _.uniq(numbers, true);
|
||||
});
|
||||
|
||||
|
||||
JSLitmus.test('_.sortBy()', function() {
|
||||
return _.sortBy(numbers, function(num){ return -num; });
|
||||
});
|
||||
|
||||
|
||||
JSLitmus.test('_.isEqual()', function() {
|
||||
return _.isEqual(numbers, randomized);
|
||||
});
|
||||
|
||||
|
||||
JSLitmus.test('_.keys()', function() {
|
||||
return _.keys(objects);
|
||||
});
|
||||
|
||||
|
||||
JSLitmus.test('_.values()', function() {
|
||||
return _.values(objects);
|
||||
});
|
||||
|
||||
|
||||
JSLitmus.test('_.intersect()', function() {
|
||||
return _.intersect(numbers, randomized);
|
||||
});
|
||||
|
||||
2
underscore-min.js
vendored
2
underscore-min.js
vendored
File diff suppressed because one or more lines are too long
@@ -28,7 +28,7 @@
|
||||
if (typeof exports !== 'undefined') _ = exports;
|
||||
|
||||
// Current version.
|
||||
_.VERSION = '0.4.1';
|
||||
_.VERSION = '0.4.2';
|
||||
|
||||
/*------------------------ Collection Functions: ---------------------------*/
|
||||
|
||||
@@ -531,7 +531,7 @@
|
||||
};
|
||||
|
||||
// Extracts the result from a wrapped and chained object.
|
||||
wrapper.prototype.get = function() {
|
||||
wrapper.prototype.value = function() {
|
||||
return this._wrapped;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user