Update vendor/underscore to v1.5.0.

Former-commit-id: 8f647bccfdd8fe81473ae7d1354056a928b6f28c
This commit is contained in:
John-David Dalton
2013-07-06 18:33:44 -07:00
parent fca2fe2c8a
commit 7d8571b0e1
8 changed files with 162 additions and 47 deletions

View File

@@ -1,4 +1,4 @@
// Underscore.js 1.4.4
// Underscore.js 1.5.0
// http://underscorejs.org
// (c) 2009-2011 Jeremy Ashkenas, DocumentCloud Inc.
// (c) 2011-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
@@ -66,7 +66,7 @@
}
// Current version.
_.VERSION = '1.4.4';
_.VERSION = '1.5.0';
// Collection Functions
// --------------------
@@ -424,6 +424,9 @@
// Internal implementation of a recursive `flatten` function.
var flatten = function(input, shallow, output) {
if (shallow && _.every(input, _.isArray)) {
return concat.apply(output, input);
}
each(input, function(value) {
if (_.isArray(value) || _.isArguments(value)) {
shallow ? push.apply(output, value) : flatten(value, shallow, output);
@@ -492,7 +495,7 @@
// Zip together multiple lists into a single array -- elements that share
// an index go together.
_.zip = function() {
return _.unzip(slice.call(arguments));
return _.unzip.apply(_, slice.call(arguments));
};
// The inverse operation to `_.zip`. If given an array of pairs it
@@ -501,11 +504,11 @@
// 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(list) {
var length = _.max(_.pluck(list, "length").concat(0));
_.unzip = function() {
var length = _.max(_.pluck(arguments, "length").concat(0));
var results = new Array(length);
for (var i = 0; i < length; i++) {
results[i] = _.pluck(list, '' + i);
results[i] = _.pluck(arguments, '' + i);
}
return results;
};
@@ -649,11 +652,15 @@
};
// Returns a function, that, when invoked, will only be triggered at most once
// during a given window of time.
_.throttle = function(func, wait, immediate) {
// during a given window of time. Normally, the throttled function will run
// as much as it can, without ever going more than once per `wait` duration;
// but if you'd like to disable the execution on the leading edge, pass
// `{leading: false}`. To disable execution on the trailing edge, ditto.
_.throttle = function(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0;
options || (options = {});
var later = function() {
previous = new Date;
timeout = null;
@@ -661,7 +668,7 @@
};
return function() {
var now = new Date;
if (!previous && immediate === false) previous = now;
if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
@@ -670,7 +677,7 @@
timeout = null;
previous = now;
result = func.apply(context, args);
} else if (!timeout) {
} else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
@@ -737,7 +744,6 @@
// Returns a function that will only be executed after being called N times.
_.after = function(times, func) {
if (times <= 0) return func();
return function() {
if (--times < 1) {
return func.apply(this, arguments);
@@ -891,6 +897,13 @@
// unique nested structures.
if (aStack[length] == a) return bStack[length] == b;
}
// Objects with different constructors are not equivalent, but `Object`s
// from different frames are.
var aCtor = a.constructor, bCtor = b.constructor;
if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
_.isFunction(bCtor) && (bCtor instanceof bCtor))) {
return false;
}
// Add the first object to the stack of traversed objects.
aStack.push(a);
bStack.push(b);
@@ -907,13 +920,6 @@
}
}
} else {
// Objects with different constructors are not equivalent, but `Object`s
// from different frames are.
var aCtor = a.constructor, bCtor = b.constructor;
if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
_.isFunction(bCtor) && (bCtor instanceof bCtor))) {
return false;
}
// Deep compare objects.
for (var key in a) {
if (_.has(a, key)) {