mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 19:37:49 +00:00
version 0.3.2, with 'identity', and Rhino support
This commit is contained in:
29
index.html
29
index.html
@@ -81,7 +81,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Underscore provides 44-odd functions that support both the usual
|
Underscore provides 45-odd functions that support both the usual
|
||||||
functional suspects: <b>map</b>, <b>select</b>, <b>invoke</b> —
|
functional suspects: <b>map</b>, <b>select</b>, <b>invoke</b> —
|
||||||
as well as more specialized helpers: function binding, javascript
|
as well as more specialized helpers: function binding, javascript
|
||||||
templating, deep equality testing, and so on. It delegates to built-in
|
templating, deep equality testing, and so on. It delegates to built-in
|
||||||
@@ -107,11 +107,11 @@
|
|||||||
<p>
|
<p>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="underscore.js">Development Version (0.3.1)</a></td>
|
<td><a href="underscore.js">Development Version (0.3.2)</a></td>
|
||||||
<td><i>16kb, Uncompressed with Comments</i></td>
|
<td><i>16kb, Uncompressed with Comments</i></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="underscore-min.js">Production Version (0.3.1)</a></td>
|
<td><a href="underscore-min.js">Production Version (0.3.2)</a></td>
|
||||||
<td><i>4kb, Packed and Gzipped</i></td>
|
<td><i>4kb, Packed and Gzipped</i></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@@ -158,7 +158,8 @@
|
|||||||
<b>Utility</b>
|
<b>Utility</b>
|
||||||
<br />
|
<br />
|
||||||
<span class="methods"><a href="#noConflict">noConflict</a>,
|
<span class="methods"><a href="#noConflict">noConflict</a>,
|
||||||
<a href="#uniqueId">uniqueId</a>, <a href="#template">template</a></span>
|
<a href="#identity">identity</a>, <a href="#uniqueId">uniqueId</a>,
|
||||||
|
<a href="#template">template</a></span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div id="documentation">
|
<div id="documentation">
|
||||||
@@ -700,6 +701,19 @@ _.isUndefined(window.missingVariable);
|
|||||||
<pre>
|
<pre>
|
||||||
var underscore = _.noConflict();</pre>
|
var underscore = _.noConflict();</pre>
|
||||||
|
|
||||||
|
<p id="identity">
|
||||||
|
<b class="header">identity</b><code>_.identity(value)</code>
|
||||||
|
<br />
|
||||||
|
Returns the same value that is used as the argument. In math:
|
||||||
|
<tt>f(x) = x</tt><br />
|
||||||
|
This function looks useless, but is used throughout Underscore as
|
||||||
|
a default iterator.
|
||||||
|
</p>
|
||||||
|
<pre>
|
||||||
|
var moe = {name : 'moe'};
|
||||||
|
moe === _.identity(moe);
|
||||||
|
=> true</pre>
|
||||||
|
|
||||||
<p id="uniqueId">
|
<p id="uniqueId">
|
||||||
<b class="header">uniqueId</b><code>_.uniqueId([prefix])</code>
|
<b class="header">uniqueId</b><code>_.uniqueId([prefix])</code>
|
||||||
<br />
|
<br />
|
||||||
@@ -736,6 +750,13 @@ _.template(list, {people : ['moe', 'curly', 'larry']});
|
|||||||
|
|
||||||
<h2>Change Log</h2>
|
<h2>Change Log</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b class="header">0.3.2</b><br />
|
||||||
|
Now runs on stock <a href="http://www.mozilla.org/rhino/">Rhino</a>
|
||||||
|
interpreters with: <tt>load("underscore.js")</tt>.
|
||||||
|
Added <a href="#identity"><tt>identity</tt></a> as a utility function.
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b class="header">0.3.1</b><br />
|
<b class="header">0.3.1</b><br />
|
||||||
All iterators are now passed in the original collection as their third
|
All iterators are now passed in the original collection as their third
|
||||||
|
|||||||
2
underscore-min.js
vendored
2
underscore-min.js
vendored
File diff suppressed because one or more lines are too long
@@ -10,23 +10,20 @@
|
|||||||
|
|
||||||
/*------------------------- Baseline setup ---------------------------------*/
|
/*------------------------- Baseline setup ---------------------------------*/
|
||||||
|
|
||||||
// Are we running in CommonJS or in the browser?
|
// Establish the root object, "window" in the browser, or "global" on the server.
|
||||||
var commonJS = (typeof window === 'undefined' && typeof exports !== 'undefined');
|
var root = this;
|
||||||
|
|
||||||
// Save the previous value of the "_" variable.
|
// Save the previous value of the "_" variable.
|
||||||
var previousUnderscore = commonJS ? null : window._;
|
var previousUnderscore = root._;
|
||||||
|
|
||||||
// Keep the identity function around for default iterators.
|
|
||||||
var identity = function(value) { return value; };
|
|
||||||
|
|
||||||
// Create a safe reference to the Underscore object for the functions below.
|
// Create a safe reference to the Underscore object for the functions below.
|
||||||
var _ = {};
|
var _ = root._ = {};
|
||||||
|
|
||||||
// Export the Underscore object for CommonJS, assign it globally otherwise.
|
// Export the Underscore object for CommonJS.
|
||||||
commonJS ? _ = exports : window._ = _;
|
if (typeof exports !== 'undefined') _ = exports;
|
||||||
|
|
||||||
// Current version.
|
// Current version.
|
||||||
_.VERSION = '0.3.1';
|
_.VERSION = '0.3.2';
|
||||||
|
|
||||||
/*------------------------ Collection Functions: ---------------------------*/
|
/*------------------------ Collection Functions: ---------------------------*/
|
||||||
|
|
||||||
@@ -107,7 +104,7 @@
|
|||||||
// Determine whether all of the elements match a truth test. Delegate to
|
// Determine whether all of the elements match a truth test. Delegate to
|
||||||
// JavaScript 1.6's every(), if it is present.
|
// JavaScript 1.6's every(), if it is present.
|
||||||
_.all = function(obj, iterator, context) {
|
_.all = function(obj, iterator, context) {
|
||||||
iterator = iterator || identity;
|
iterator = iterator || _.identity;
|
||||||
if (obj.every) return obj.every(iterator, context);
|
if (obj.every) return obj.every(iterator, context);
|
||||||
var result = true;
|
var result = true;
|
||||||
_.each(obj, function(value, index, list) {
|
_.each(obj, function(value, index, list) {
|
||||||
@@ -119,7 +116,7 @@
|
|||||||
// Determine if at least one element in the object matches a truth test. Use
|
// Determine if at least one element in the object matches a truth test. Use
|
||||||
// JavaScript 1.6's some(), if it exists.
|
// JavaScript 1.6's some(), if it exists.
|
||||||
_.any = function(obj, iterator, context) {
|
_.any = function(obj, iterator, context) {
|
||||||
iterator = iterator || identity;
|
iterator = iterator || _.identity;
|
||||||
if (obj.some) return obj.some(iterator, context);
|
if (obj.some) return obj.some(iterator, context);
|
||||||
var result = false;
|
var result = false;
|
||||||
_.each(obj, function(value, index, list) {
|
_.each(obj, function(value, index, list) {
|
||||||
@@ -192,7 +189,7 @@
|
|||||||
// Use a comparator function to figure out at what index an object should
|
// Use a comparator function to figure out at what index an object should
|
||||||
// be inserted so as to maintain order. Uses binary search.
|
// be inserted so as to maintain order. Uses binary search.
|
||||||
_.sortedIndex = function(array, obj, iterator) {
|
_.sortedIndex = function(array, obj, iterator) {
|
||||||
iterator = iterator || identity;
|
iterator = iterator || _.identity;
|
||||||
var low = 0, high = array.length;
|
var low = 0, high = array.length;
|
||||||
while (low < high) {
|
while (low < high) {
|
||||||
var mid = (low + high) >> 1;
|
var mid = (low + high) >> 1;
|
||||||
@@ -360,7 +357,7 @@
|
|||||||
|
|
||||||
// Retrieve the values of an object's properties.
|
// Retrieve the values of an object's properties.
|
||||||
_.values = function(obj) {
|
_.values = function(obj) {
|
||||||
return _.map(obj, identity);
|
return _.map(obj, _.identity);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Extend a given object with all of the properties in a source object.
|
// Extend a given object with all of the properties in a source object.
|
||||||
@@ -421,10 +418,15 @@
|
|||||||
// Run Underscore.js in noConflict mode, returning the '_' variable to its
|
// Run Underscore.js in noConflict mode, returning the '_' variable to its
|
||||||
// previous owner. Returns a reference to the Underscore object.
|
// previous owner. Returns a reference to the Underscore object.
|
||||||
_.noConflict = function() {
|
_.noConflict = function() {
|
||||||
if (!commonJS) window._ = previousUnderscore;
|
root._ = previousUnderscore;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Keep the identity function around for default iterators.
|
||||||
|
_.identity = function(value) {
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
// Generate a unique integer id (unique within the entire client session).
|
// Generate a unique integer id (unique within the entire client session).
|
||||||
// Useful for temporary DOM ids.
|
// Useful for temporary DOM ids.
|
||||||
_.uniqueId = function(prefix) {
|
_.uniqueId = function(prefix) {
|
||||||
|
|||||||
Reference in New Issue
Block a user