Skip to content

Commit

Permalink
bump to 1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kellysutton committed Jul 12, 2013
1 parent 5efa39d commit fe927ed
Showing 1 changed file with 49 additions and 41 deletions.
90 changes: 49 additions & 41 deletions vendor/assets/javascripts/underscore.js
@@ -1,6 +1,6 @@
// Underscore.js 1.4.4
// Underscore.js 1.5.1
// http://underscorejs.org
// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
// Underscore may be freely distributed under the MIT license.

(function() {
Expand All @@ -21,11 +21,12 @@
var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;

// Create quick reference variables for speed access to core prototypes.
var push = ArrayProto.push,
slice = ArrayProto.slice,
concat = ArrayProto.concat,
toString = ObjProto.toString,
hasOwnProperty = ObjProto.hasOwnProperty;
var
push = ArrayProto.push,
slice = ArrayProto.slice,
concat = ArrayProto.concat,
toString = ObjProto.toString,
hasOwnProperty = ObjProto.hasOwnProperty;

// All **ECMAScript 5** native function implementations that we hope to use
// are declared here.
Expand Down Expand Up @@ -64,7 +65,7 @@
}

// Current version.
_.VERSION = '1.4.4';
_.VERSION = '1.5.1';

// Collection Functions
// --------------------
Expand Down Expand Up @@ -96,7 +97,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;
};
Expand Down Expand Up @@ -171,7 +172,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;
};
Expand Down Expand Up @@ -255,7 +256,7 @@

// Return the maximum element or (element-based computation).
// Can't optimize arrays of integers longer than 65,535 elements.
// See: https://bugs.webkit.org/show_bug.cgi?id=80797
// See [WebKit Bug 80797](https://bugs.webkit.org/show_bug.cgi?id=80797)
_.max = function(obj, iterator, context) {
if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
return Math.max.apply(Math, obj);
Expand All @@ -264,7 +265,7 @@
var result = {computed : -Infinity, value: -Infinity};
each(obj, function(value, index, list) {
var computed = iterator ? iterator.call(context, value, index, list) : value;
computed >= result.computed && (result = {value : value, computed : computed});
computed > result.computed && (result = {value : value, computed : computed});
});
return result.value;
};
Expand Down Expand Up @@ -363,7 +364,7 @@
return low;
};

// Safely convert anything iterable into a real, live array.
// Safely create a real, live array from anything iterable.
_.toArray = function(obj) {
if (!obj) return [];
if (_.isArray(obj)) return slice.call(obj);
Expand Down Expand Up @@ -422,8 +423,11 @@

// 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)) {
if (_.isArray(value) || _.isArguments(value)) {
shallow ? push.apply(output, value) : flatten(value, shallow, output);
} else {
output.push(value);
Expand Down Expand Up @@ -466,7 +470,7 @@
// Produce an array that contains the union: each distinct element from all of
// the passed-in arrays.
_.union = function() {
return _.uniq(concat.apply(ArrayProto, arguments));
return _.uniq(_.flatten(arguments, true));
};

// Produce an array that contains every item shared between all the
Expand All @@ -490,11 +494,10 @@
// Zip together multiple lists into a single array -- elements that share
// an index go together.
_.zip = function() {
var args = slice.call(arguments);
var length = _.max(_.pluck(args, 'length'));
var length = _.max(_.pluck(arguments, "length").concat(0));
var results = new Array(length);
for (var i = 0; i < length; i++) {
results[i] = _.pluck(args, "" + i);
results[i] = _.pluck(arguments, '' + i);
}
return results;
};
Expand Down Expand Up @@ -582,7 +585,7 @@
// available.
_.bind = function(func, context) {
var args, bound;
if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
if (!_.isFunction(func)) throw new TypeError;
args = slice.call(arguments, 2);
return bound = function() {
Expand Down Expand Up @@ -638,17 +641,23 @@
};

// Returns a function, that, when invoked, will only be triggered at most once
// during a given window of time.
_.throttle = function(func, wait) {
var context, args, timeout, result;
// 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;
previous = options.leading === false ? 0 : new Date;
timeout = null;
result = func.apply(context, args);
};
return function() {
var now = new Date;
if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
Expand All @@ -657,7 +666,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;
Expand All @@ -669,7 +678,8 @@
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
_.debounce = function(func, wait, immediate) {
var timeout, result;
var result;
var timeout = null;
return function() {
var context = this, args = arguments;
var later = function() {
Expand Down Expand Up @@ -723,7 +733,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);
Expand All @@ -739,7 +748,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;
};

Expand Down Expand Up @@ -835,7 +844,7 @@
// Internal recursive comparison function for `isEqual`.
var eq = function(a, b, aStack, bStack) {
// 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.
// See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
if (a === b) return a !== 0 || 1 / a == 1 / b;
// A strict comparison is necessary because `null == undefined`.
if (a == null || b == null) return a === b;
Expand Down Expand Up @@ -877,6 +886,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);
Expand All @@ -893,13 +909,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)) {
Expand Down Expand Up @@ -1023,7 +1032,7 @@

// Run a function **n** times.
_.times = function(n, iterator, context) {
var accum = Array(n);
var accum = Array(Math.max(0, n));
for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i);
return accum;
};
Expand All @@ -1044,8 +1053,7 @@
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;',
'/': '&#x2F;'
"'": '&#x27;'
}
};
entityMap.unescape = _.invert(entityMap.escape);
Expand All @@ -1066,8 +1074,8 @@
};
});

// 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 void 0;
var value = object[property];
Expand Down Expand Up @@ -1234,4 +1242,4 @@

});

}).call(this);
}).call(this);

0 comments on commit fe927ed

Please sign in to comment.