mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-13 12:27:49 +00:00
Update vendor/underscore and backbone.
Former-commit-id: 614926653b0b1669f8a5533666adb0aecbd46c03
This commit is contained in:
40
vendor/underscore/underscore.js
vendored
40
vendor/underscore/underscore.js
vendored
@@ -267,7 +267,7 @@
|
||||
|
||||
// Sort the object's values by a criterion produced by an iterator.
|
||||
_.sortBy = function(obj, val, context) {
|
||||
var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; };
|
||||
var iterator = lookupIterator(obj, val);
|
||||
return _.pluck(_.map(obj, function(value, index, list) {
|
||||
return {
|
||||
value : value,
|
||||
@@ -281,16 +281,38 @@
|
||||
}), 'value');
|
||||
};
|
||||
|
||||
// An internal function to generate lookup iterators.
|
||||
var lookupIterator = function(obj, val) {
|
||||
return _.isFunction(val) ? val : function(obj) { return obj[val]; };
|
||||
};
|
||||
|
||||
// An internal function used for aggregate "group by" operations.
|
||||
var group = function(obj, val, behavior) {
|
||||
var result = {};
|
||||
var iterator = lookupIterator(obj, val);
|
||||
each(obj, function(value, index) {
|
||||
var key = iterator(value, index);
|
||||
behavior(result, key, value);
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
// Groups the object's values by a criterion. Pass either a string attribute
|
||||
// to group by, or a function that returns the criterion.
|
||||
_.groupBy = function(obj, val) {
|
||||
var result = {};
|
||||
var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; };
|
||||
each(obj, function(value, index) {
|
||||
var key = iterator(value, index);
|
||||
return group(obj, val, function(result, key, value) {
|
||||
(result[key] || (result[key] = [])).push(value);
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
// Counts instances of an object that group by a certain criterion. Pass
|
||||
// either a string attribute to count by, or a function that returns the
|
||||
// criterion.
|
||||
_.countBy = function(obj, val) {
|
||||
return group(obj, val, function(result, key, value) {
|
||||
result[key] || (result[key] = 0);
|
||||
result[key]++;
|
||||
});
|
||||
};
|
||||
|
||||
// Use a comparator function to figure out the smallest index at which
|
||||
@@ -709,7 +731,7 @@
|
||||
};
|
||||
|
||||
// Internal recursive comparison function for `isEqual`.
|
||||
function eq(a, b, stack) {
|
||||
var eq = function(a, b, stack) {
|
||||
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
||||
// See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal.
|
||||
if (a === b) return a !== 0 || 1 / a == 1 / b;
|
||||
@@ -794,7 +816,7 @@
|
||||
// Remove the first object from the stack of traversed objects.
|
||||
stack.pop();
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
// Perform a deep comparison to check if two objects are equal.
|
||||
_.isEqual = function(a, b) {
|
||||
@@ -832,7 +854,7 @@
|
||||
return toString.call(obj) == '[object ' + name + ']';
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
// Define a fallback version of the method in browsers (ahem, IE), where
|
||||
// there isn't any inspectable "Arguments" type.
|
||||
if (!_.isArguments(arguments)) {
|
||||
|
||||
Reference in New Issue
Block a user