Skip to content

Commit

Permalink
updating to latest underscore.js v1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Fitzgerald committed Jan 26, 2012
1 parent 3a1b764 commit 6be29dd
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions vendor/assets/javascripts/underscore.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Underscore.js 1.3.0
// Underscore.js 1.3.1
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore is freely distributable under the MIT license.
// Portions of Underscore are inspired or borrowed from Prototype,
Expand Down Expand Up @@ -62,7 +62,7 @@
}

// Current version.
_.VERSION = '1.3.0';
_.VERSION = '1.3.1';

// Collection Functions
// --------------------
Expand All @@ -80,7 +80,7 @@
}
} else {
for (var key in obj) {
if (hasOwnProperty.call(obj, key)) {
if (_.has(obj, key)) {
if (iterator.call(context, obj[key], key, obj) === breaker) return;
}
}
Expand All @@ -89,7 +89,7 @@

// Return the results of applying the iterator to each element.
// Delegates to **ECMAScript 5**'s native `map` if available.
_.map = function(obj, iterator, context) {
_.map = _.collect = function(obj, iterator, context) {
var results = [];
if (obj == null) return results;
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
Expand Down Expand Up @@ -506,7 +506,7 @@
hasher || (hasher = _.identity);
return function() {
var key = hasher.apply(this, arguments);
return hasOwnProperty.call(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
};
};

Expand Down Expand Up @@ -612,7 +612,7 @@
_.keys = nativeKeys || function(obj) {
if (obj !== Object(obj)) throw new TypeError('Invalid object');
var keys = [];
for (var key in obj) if (hasOwnProperty.call(obj, key)) keys[keys.length] = key;
for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key;
return keys;
};

Expand All @@ -635,7 +635,7 @@
_.extend = function(obj) {
each(slice.call(arguments, 1), function(source) {
for (var prop in source) {
if (source[prop] !== void 0) obj[prop] = source[prop];
obj[prop] = source[prop];
}
});
return obj;
Expand Down Expand Up @@ -733,17 +733,17 @@
if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false;
// Deep compare objects.
for (var key in a) {
if (hasOwnProperty.call(a, key)) {
if (_.has(a, key)) {
// Count the expected number of properties.
size++;
// Deep compare each member.
if (!(result = hasOwnProperty.call(b, key) && eq(a[key], b[key], stack))) break;
if (!(result = _.has(b, key) && eq(a[key], b[key], stack))) break;
}
}
// Ensure that both objects contain the same number of properties.
if (result) {
for (key in b) {
if (hasOwnProperty.call(b, key) && !(size--)) break;
if (_.has(b, key) && !(size--)) break;
}
result = !size;
}
Expand All @@ -762,7 +762,7 @@
// An "empty" object has no enumerable own-properties.
_.isEmpty = function(obj) {
if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
for (var key in obj) if (hasOwnProperty.call(obj, key)) return false;
for (var key in obj) if (_.has(obj, key)) return false;
return true;
};

Expand All @@ -788,7 +788,7 @@
};
if (!_.isArguments(arguments)) {
_.isArguments = function(obj) {
return !!(obj && hasOwnProperty.call(obj, 'callee'));
return !!(obj && _.has(obj, 'callee'));
};
}

Expand Down Expand Up @@ -838,6 +838,11 @@
return obj === void 0;
};

// Has own property?
_.has = function(obj, key) {
return hasOwnProperty.call(obj, key);
};

// Utility Functions
// -----------------

Expand Down Expand Up @@ -892,6 +897,12 @@
// guaranteed not to match.
var noMatch = /.^/;

// Within an interpolation, evaluation, or escaping, remove HTML escaping
// that had been previously added.
var unescape = function(code) {
return code.replace(/\\\\/g, '\\').replace(/\\'/g, "'");
};

// JavaScript micro-templating, similar to John Resig's implementation.
// Underscore templating handles arbitrary delimiters, preserves whitespace,
// and correctly escapes quotes within interpolated code.
Expand All @@ -902,15 +913,13 @@
str.replace(/\\/g, '\\\\')
.replace(/'/g, "\\'")
.replace(c.escape || noMatch, function(match, code) {
return "',_.escape(" + code.replace(/\\'/g, "'") + "),'";
return "',_.escape(" + unescape(code) + "),'";
})
.replace(c.interpolate || noMatch, function(match, code) {
return "'," + code.replace(/\\'/g, "'") + ",'";
return "'," + unescape(code) + ",'";
})
.replace(c.evaluate || noMatch, function(match, code) {
return "');" + code.replace(/\\'/g, "'")
.replace(/[\r\n\t]/g, ' ')
.replace(/\\\\/g, '\\') + ";__p.push('";
return "');" + unescape(code).replace(/[\r\n\t]/g, ' ') + ";__p.push('";
})
.replace(/\r/g, '\\r')
.replace(/\n/g, '\\n')
Expand Down

0 comments on commit 6be29dd

Please sign in to comment.