mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Update vendor/underscore.
Former-commit-id: d1cca79a4f6732ee8cd48dd4574041b4ebe19edf
This commit is contained in:
2
vendor/underscore/underscore-min.js
vendored
2
vendor/underscore/underscore-min.js
vendored
File diff suppressed because one or more lines are too long
59
vendor/underscore/underscore.js
vendored
59
vendor/underscore/underscore.js
vendored
@@ -96,7 +96,7 @@
|
||||
if (obj == null) return results;
|
||||
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
|
||||
each(obj, function(value, index, list) {
|
||||
results[results.length] = iterator.call(context, value, index, list);
|
||||
results.push(iterator.call(context, value, index, list));
|
||||
});
|
||||
return results;
|
||||
};
|
||||
@@ -171,7 +171,7 @@
|
||||
if (obj == null) return results;
|
||||
if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context);
|
||||
each(obj, function(value, index, list) {
|
||||
if (iterator.call(context, value, index, list)) results[results.length] = value;
|
||||
if (iterator.call(context, value, index, list)) results.push(value);
|
||||
});
|
||||
return results;
|
||||
};
|
||||
@@ -238,7 +238,7 @@
|
||||
// Convenience version of a common use case of `filter`: selecting only objects
|
||||
// containing specific `key:value` pairs.
|
||||
_.where = function(obj, attrs, first) {
|
||||
if (_.isEmpty(attrs)) return first ? null : [];
|
||||
if (_.isEmpty(attrs)) return first ? void 0 : [];
|
||||
return _[first ? 'find' : 'filter'](obj, function(value) {
|
||||
for (var key in attrs) {
|
||||
if (attrs[key] !== value[key]) return false;
|
||||
@@ -324,7 +324,7 @@
|
||||
// An internal function used for aggregate "group by" operations.
|
||||
var group = function(obj, value, context, behavior) {
|
||||
var result = {};
|
||||
var iterator = lookupIterator(value || _.identity);
|
||||
var iterator = lookupIterator(value == null ? _.identity : value);
|
||||
each(obj, function(value, index) {
|
||||
var key = iterator.call(context, value, index, obj);
|
||||
behavior(result, key, value);
|
||||
@@ -499,6 +499,25 @@
|
||||
return results;
|
||||
};
|
||||
|
||||
// The inverse operation to `_.zip`. If given an array of pairs it
|
||||
// returns an array of the paired elements split into two left and
|
||||
// right element arrays, if given an array of triples it returns a
|
||||
// three element array and so on. For example, `_.unzip` given
|
||||
// `[['a',1],['b',2],['c',3]]` returns the array
|
||||
// [['a','b','c'],[1,2,3]].
|
||||
_.unzip = function(tuples) {
|
||||
var results = [];
|
||||
_.each(tuples, function (tuple, tupleIndex) {
|
||||
_.each(tuple, function (value, itemIndex) {
|
||||
if (results.length <= itemIndex) {
|
||||
results[itemIndex] = [];
|
||||
}
|
||||
results[itemIndex][tupleIndex] = value;
|
||||
});
|
||||
});
|
||||
return results;
|
||||
};
|
||||
|
||||
// Converts lists into objects. Pass either a single array of `[key, value]`
|
||||
// pairs, or two parallel arrays of the same length -- one of keys, and one of
|
||||
// the corresponding values.
|
||||
@@ -574,14 +593,25 @@
|
||||
// Function (ahem) Functions
|
||||
// ------------------
|
||||
|
||||
// Reusable constructor function for prototype setting.
|
||||
var ctor = function(){};
|
||||
|
||||
// Create a function bound to a given object (assigning `this`, and arguments,
|
||||
// optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
|
||||
// available.
|
||||
_.bind = function(func, context) {
|
||||
var args, bound;
|
||||
if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
|
||||
var args = slice.call(arguments, 2);
|
||||
return function() {
|
||||
return func.apply(context, args.concat(slice.call(arguments)));
|
||||
if (!_.isFunction(func)) throw new TypeError;
|
||||
args = slice.call(arguments, 2);
|
||||
return bound = function() {
|
||||
if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
|
||||
ctor.prototype = func.prototype;
|
||||
var self = new ctor;
|
||||
ctor.prototype = null;
|
||||
var result = func.apply(self, args.concat(slice.call(arguments)));
|
||||
if (Object(result) === result) return result;
|
||||
return self;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -598,7 +628,7 @@
|
||||
// all callbacks defined on an object belong to it.
|
||||
_.bindAll = function(obj) {
|
||||
var funcs = slice.call(arguments, 1);
|
||||
if (funcs.length === 0) funcs = _.functions(obj);
|
||||
if (funcs.length === 0) throw new Error("bindAll must be passed function names");
|
||||
each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
|
||||
return obj;
|
||||
};
|
||||
@@ -628,7 +658,7 @@
|
||||
|
||||
// Returns a function, that, when invoked, will only be triggered at most once
|
||||
// during a given window of time.
|
||||
_.throttle = function(func, wait) {
|
||||
_.throttle = function(func, wait, immediate) {
|
||||
var context, args, timeout, result;
|
||||
var previous = 0;
|
||||
var later = function() {
|
||||
@@ -638,6 +668,7 @@
|
||||
};
|
||||
return function() {
|
||||
var now = new Date;
|
||||
if (!previous && immediate === false) previous = now;
|
||||
var remaining = wait - (now - previous);
|
||||
context = this;
|
||||
args = arguments;
|
||||
@@ -728,7 +759,7 @@
|
||||
_.keys = nativeKeys || function(obj) {
|
||||
if (obj !== Object(obj)) throw new TypeError('Invalid object');
|
||||
var keys = [];
|
||||
for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key;
|
||||
for (var key in obj) if (_.has(obj, key)) keys.push(key);
|
||||
return keys;
|
||||
};
|
||||
|
||||
@@ -800,7 +831,7 @@
|
||||
each(slice.call(arguments, 1), function(source) {
|
||||
if (source) {
|
||||
for (var prop in source) {
|
||||
if (obj[prop] == null) obj[prop] = source[prop];
|
||||
if (obj[prop] === void 0) obj[prop] = source[prop];
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1055,10 +1086,10 @@
|
||||
};
|
||||
});
|
||||
|
||||
// If the value of the named property is a function then invoke it;
|
||||
// otherwise, return it.
|
||||
// If the value of the named `property` is a function then invoke it with the
|
||||
// `object` as context; otherwise, return it.
|
||||
_.result = function(object, property) {
|
||||
if (object == null) return null;
|
||||
if (object == null) return void 0;
|
||||
var value = object[property];
|
||||
return _.isFunction(value) ? value.call(object) : value;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user