mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +00:00
Use typeof == 'number' more, and default callback values to docs.
Former-commit-id: 02786903a510d0cc837eeeb7e9f42db2ecd634a4
This commit is contained in:
28
lodash.js
28
lodash.js
@@ -199,7 +199,7 @@
|
|||||||
// the following branch is for iterating arrays and array-like objects
|
// the following branch is for iterating arrays and array-like objects
|
||||||
'<% if (arrayBranch) { %>' +
|
'<% if (arrayBranch) { %>' +
|
||||||
'var length = <%= firstArg %>.length; index = -1;' +
|
'var length = <%= firstArg %>.length; index = -1;' +
|
||||||
' <% if (objectBranch) { %>\nif (length === +length) {<% } %>\n' +
|
' <% if (objectBranch) { %>\nif (typeof length == \'number\') {<% } %>\n' +
|
||||||
' <%= arrayBranch.beforeLoop %>;\n' +
|
' <%= arrayBranch.beforeLoop %>;\n' +
|
||||||
' while (<%= arrayBranch.loopExp %>) {\n' +
|
' while (<%= arrayBranch.loopExp %>) {\n' +
|
||||||
' <%= arrayBranch.inLoop %>;\n' +
|
' <%= arrayBranch.inLoop %>;\n' +
|
||||||
@@ -568,7 +568,7 @@
|
|||||||
* @alias all
|
* @alias all
|
||||||
* @category Collections
|
* @category Collections
|
||||||
* @param {Array|Object} collection The collection to iterate over.
|
* @param {Array|Object} collection The collection to iterate over.
|
||||||
* @param {Function} callback The function called per iteration.
|
* @param {Function} [callback=identity] The function called per iteration.
|
||||||
* @param {Mixed} [thisArg] The `this` binding for the callback.
|
* @param {Mixed} [thisArg] The `this` binding for the callback.
|
||||||
* @returns {Boolean} Returns `true` if all values pass the callback check, else `false`.
|
* @returns {Boolean} Returns `true` if all values pass the callback check, else `false`.
|
||||||
* @example
|
* @example
|
||||||
@@ -589,7 +589,7 @@
|
|||||||
* @alias select
|
* @alias select
|
||||||
* @category Collections
|
* @category Collections
|
||||||
* @param {Array|Object} collection The collection to iterate over.
|
* @param {Array|Object} collection The collection to iterate over.
|
||||||
* @param {Function} callback The function called per iteration.
|
* @param {Function} [callback=identity] The function called per iteration.
|
||||||
* @param {Mixed} [thisArg] The `this` binding for the callback.
|
* @param {Mixed} [thisArg] The `this` binding for the callback.
|
||||||
* @returns {Array} Returns a new array of values that passed callback check.
|
* @returns {Array} Returns a new array of values that passed callback check.
|
||||||
* @example
|
* @example
|
||||||
@@ -659,7 +659,7 @@
|
|||||||
* @alias collect
|
* @alias collect
|
||||||
* @category Collections
|
* @category Collections
|
||||||
* @param {Array|Object} collection The collection to iterate over.
|
* @param {Array|Object} collection The collection to iterate over.
|
||||||
* @param {Function} callback The function called per iteration.
|
* @param {Function} [callback=identity] The function called per iteration.
|
||||||
* @param {Mixed} [thisArg] The `this` binding for the callback.
|
* @param {Mixed} [thisArg] The `this` binding for the callback.
|
||||||
* @returns {Array} Returns a new array of values returned by the callback.
|
* @returns {Array} Returns a new array of values returned by the callback.
|
||||||
* @example
|
* @example
|
||||||
@@ -773,7 +773,7 @@
|
|||||||
if(thisArg) {
|
if(thisArg) {
|
||||||
callback = iteratorBind(callback, thisArg);
|
callback = iteratorBind(callback, thisArg);
|
||||||
}
|
}
|
||||||
if (length === +length) {
|
if (typeof length == 'number') {
|
||||||
if (length && noaccum) {
|
if (length && noaccum) {
|
||||||
accumulator = collection[--length];
|
accumulator = collection[--length];
|
||||||
}
|
}
|
||||||
@@ -807,7 +807,7 @@
|
|||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Collections
|
* @category Collections
|
||||||
* @param {Array|Object} collection The collection to iterate over.
|
* @param {Array|Object} collection The collection to iterate over.
|
||||||
* @param {Function} callback The function called per iteration.
|
* @param {Function} [callback=identity] The function called per iteration.
|
||||||
* @param {Mixed} [thisArg] The `this` binding for the callback.
|
* @param {Mixed} [thisArg] The `this` binding for the callback.
|
||||||
* @returns {Array} Returns a new array of values that did **not** pass the callback check.
|
* @returns {Array} Returns a new array of values that did **not** pass the callback check.
|
||||||
* @example
|
* @example
|
||||||
@@ -831,7 +831,7 @@
|
|||||||
* @alias any
|
* @alias any
|
||||||
* @category Collections
|
* @category Collections
|
||||||
* @param {Array|Object} collection The collection to iterate over.
|
* @param {Array|Object} collection The collection to iterate over.
|
||||||
* @param {Function} callback The function called per iteration.
|
* @param {Function} [callback=identity] The function called per iteration.
|
||||||
* @param {Mixed} [thisArg] The `this` binding for the callback.
|
* @param {Mixed} [thisArg] The `this` binding for the callback.
|
||||||
* @returns {Boolean} Returns `true` if any value passes the callback check, else `false`.
|
* @returns {Boolean} Returns `true` if any value passes the callback check, else `false`.
|
||||||
* @example
|
* @example
|
||||||
@@ -866,7 +866,7 @@
|
|||||||
return collection.toArray();
|
return collection.toArray();
|
||||||
}
|
}
|
||||||
var length = collection.length;
|
var length = collection.length;
|
||||||
if (length === +length) {
|
if (typeof length == 'number') {
|
||||||
return slice.call(collection);
|
return slice.call(collection);
|
||||||
}
|
}
|
||||||
return values(collection);
|
return values(collection);
|
||||||
@@ -1082,7 +1082,7 @@
|
|||||||
* // => ['moe', 'larry', 'brendan']
|
* // => ['moe', 'larry', 'brendan']
|
||||||
*/
|
*/
|
||||||
function sortBy(array, callback, thisArg) {
|
function sortBy(array, callback, thisArg) {
|
||||||
if (toString.call(callback) != funcClass) {
|
if (typeof callback == 'string') {
|
||||||
var prop = callback;
|
var prop = callback;
|
||||||
callback = function(array) { return array[prop]; };
|
callback = function(array) { return array[prop]; };
|
||||||
} else if (thisArg) {
|
} else if (thisArg) {
|
||||||
@@ -1136,7 +1136,7 @@
|
|||||||
length = array.length;
|
length = array.length;
|
||||||
|
|
||||||
if (fromIndex) {
|
if (fromIndex) {
|
||||||
if (fromIndex === +fromIndex) {
|
if (typeof fromIndex == 'number') {
|
||||||
index = (fromIndex < 0 ? Math.max(0, length + fromIndex) : fromIndex) - 1;
|
index = (fromIndex < 0 ? Math.max(0, length + fromIndex) : fromIndex) - 1;
|
||||||
} else {
|
} else {
|
||||||
index = sortedIndex(array, value);
|
index = sortedIndex(array, value);
|
||||||
@@ -1275,7 +1275,7 @@
|
|||||||
*/
|
*/
|
||||||
function lastIndexOf(array, value, fromIndex) {
|
function lastIndexOf(array, value, fromIndex) {
|
||||||
var index = array.length;
|
var index = array.length;
|
||||||
if (fromIndex && fromIndex === +fromIndex) {
|
if (fromIndex && typeof fromIndex == 'number') {
|
||||||
index = (fromIndex < 0 ? Math.max(0, index + fromIndex) : Math.min(fromIndex, index - 1)) + 1;
|
index = (fromIndex < 0 ? Math.max(0, index + fromIndex) : Math.min(fromIndex, index - 1)) + 1;
|
||||||
}
|
}
|
||||||
while (index--) {
|
while (index--) {
|
||||||
@@ -1484,9 +1484,9 @@
|
|||||||
/**
|
/**
|
||||||
* Uses a binary search to determine the smallest index at which the `value`
|
* Uses a binary search to determine the smallest index at which the `value`
|
||||||
* should be inserted into the `array` in order to maintain the sort order
|
* should be inserted into the `array` in order to maintain the sort order
|
||||||
* of the `array`. If `callback` is passed, it will be executed for each
|
* of the `array`. If `callback` is passed, it will be executed for `value` and
|
||||||
* value in the `array` to compute their sort ranking. The `callback` is
|
* each element in the `array` to compute their sort ranking. The `callback`
|
||||||
* invoked with 1 argument; (value).
|
* is invoked with 1 argument; (value).
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
Reference in New Issue
Block a user