|
|
@ -45,8 +45,8 @@ |
|
|
|
// Export the Underscore object for **Node.js**, with
|
|
|
|
// Export the Underscore object for **Node.js**, with
|
|
|
|
// backwards-compatibility for the old `require()` API. If we're in
|
|
|
|
// backwards-compatibility for the old `require()` API. If we're in
|
|
|
|
// the browser, add `_` as a global object.
|
|
|
|
// the browser, add `_` as a global object.
|
|
|
|
if (typeof exports !== 'undefined') { |
|
|
|
if (typeof exports !== "undefined") { |
|
|
|
if (typeof module !== 'undefined' && module.exports) { |
|
|
|
if (typeof module !== "undefined" && module.exports) { |
|
|
|
exports = module.exports = _; |
|
|
|
exports = module.exports = _; |
|
|
|
} |
|
|
|
} |
|
|
|
exports._ = _; |
|
|
|
exports._ = _; |
|
|
@ -55,7 +55,7 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Current version.
|
|
|
|
// Current version.
|
|
|
|
_.VERSION = '1.8.2'; |
|
|
|
_.VERSION = "1.8.2"; |
|
|
|
|
|
|
|
|
|
|
|
// Internal function that returns an efficient (for current engines) version
|
|
|
|
// Internal function that returns an efficient (for current engines) version
|
|
|
|
// of the passed-in callback, to be repeatedly applied in other Underscore
|
|
|
|
// of the passed-in callback, to be repeatedly applied in other Underscore
|
|
|
@ -128,7 +128,7 @@ |
|
|
|
var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1; |
|
|
|
var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1; |
|
|
|
var isArrayLike = function (collection) { |
|
|
|
var isArrayLike = function (collection) { |
|
|
|
var length = collection != null && collection.length; |
|
|
|
var length = collection != null && collection.length; |
|
|
|
return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX; |
|
|
|
return typeof length === "number" && length >= 0 && length <= MAX_ARRAY_INDEX; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Collection Functions
|
|
|
|
// Collection Functions
|
|
|
@ -256,7 +256,7 @@ |
|
|
|
// Aliased as `includes` and `include`.
|
|
|
|
// Aliased as `includes` and `include`.
|
|
|
|
_.contains = _.includes = _.include = function (obj, target, fromIndex) { |
|
|
|
_.contains = _.includes = _.include = function (obj, target, fromIndex) { |
|
|
|
if (!isArrayLike(obj)) obj = _.values(obj); |
|
|
|
if (!isArrayLike(obj)) obj = _.values(obj); |
|
|
|
return _.indexOf(obj, target, typeof fromIndex == 'number' && fromIndex) >= 0; |
|
|
|
return _.indexOf(obj, target, typeof fromIndex === "number" && fromIndex) >= 0; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Invoke a method (with arguments) on every item in a collection.
|
|
|
|
// Invoke a method (with arguments) on every item in a collection.
|
|
|
@ -378,7 +378,7 @@ |
|
|
|
if (a < b || b === void 0) return -1; |
|
|
|
if (a < b || b === void 0) return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
return left.index - right.index; |
|
|
|
return left.index - right.index; |
|
|
|
}), 'value'); |
|
|
|
}), "value"); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// An internal function used for aggregate "group by" operations.
|
|
|
|
// An internal function used for aggregate "group by" operations.
|
|
|
@ -579,7 +579,7 @@ |
|
|
|
// Complement of _.zip. Unzip accepts an array of arrays and groups
|
|
|
|
// Complement of _.zip. Unzip accepts an array of arrays and groups
|
|
|
|
// each array's elements on shared indices
|
|
|
|
// each array's elements on shared indices
|
|
|
|
_.unzip = function (array) { |
|
|
|
_.unzip = function (array) { |
|
|
|
var length = array && _.max(array, 'length').length || 0; |
|
|
|
var length = array && _.max(array, "length").length || 0; |
|
|
|
var result = Array(length); |
|
|
|
var result = Array(length); |
|
|
|
|
|
|
|
|
|
|
|
for (var index = 0; index < length; index++) { |
|
|
|
for (var index = 0; index < length; index++) { |
|
|
@ -609,7 +609,7 @@ |
|
|
|
// for **isSorted** to use binary search.
|
|
|
|
// for **isSorted** to use binary search.
|
|
|
|
_.indexOf = function (array, item, isSorted) { |
|
|
|
_.indexOf = function (array, item, isSorted) { |
|
|
|
var i = 0, length = array && array.length; |
|
|
|
var i = 0, length = array && array.length; |
|
|
|
if (typeof isSorted == 'number') { |
|
|
|
if (typeof isSorted === "number") { |
|
|
|
i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted; |
|
|
|
i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted; |
|
|
|
} else if (isSorted && length) { |
|
|
|
} else if (isSorted && length) { |
|
|
|
i = _.sortedIndex(array, item); |
|
|
|
i = _.sortedIndex(array, item); |
|
|
@ -624,7 +624,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
_.lastIndexOf = function (array, item, from) { |
|
|
|
_.lastIndexOf = function (array, item, from) { |
|
|
|
var idx = array ? array.length : 0; |
|
|
|
var idx = array ? array.length : 0; |
|
|
|
if (typeof from == 'number') { |
|
|
|
if (typeof from === "number") { |
|
|
|
idx = from < 0 ? idx + from + 1 : Math.min(idx, from + 1); |
|
|
|
idx = from < 0 ? idx + from + 1 : Math.min(idx, from + 1); |
|
|
|
} |
|
|
|
} |
|
|
|
if (item !== item) { |
|
|
|
if (item !== item) { |
|
|
@ -703,7 +703,7 @@ |
|
|
|
// available.
|
|
|
|
// available.
|
|
|
|
_.bind = function (func, context) { |
|
|
|
_.bind = function (func, context) { |
|
|
|
if (nativeBind && func.bind === 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('Bind must be called on a function'); |
|
|
|
if (!_.isFunction(func)) throw new TypeError("Bind must be called on a function"); |
|
|
|
var args = slice.call(arguments, 2); |
|
|
|
var args = slice.call(arguments, 2); |
|
|
|
var bound = function () { |
|
|
|
var bound = function () { |
|
|
|
return executeBound(func, bound, context, this, args.concat(slice.call(arguments))); |
|
|
|
return executeBound(func, bound, context, this, args.concat(slice.call(arguments))); |
|
|
@ -733,7 +733,7 @@ |
|
|
|
// defined on an object belong to it.
|
|
|
|
// defined on an object belong to it.
|
|
|
|
_.bindAll = function (obj) { |
|
|
|
_.bindAll = function (obj) { |
|
|
|
var i, length = arguments.length, key; |
|
|
|
var i, length = arguments.length, key; |
|
|
|
if (length <= 1) throw new Error('bindAll must be passed function names'); |
|
|
|
if (length <= 1) throw new Error("bindAll must be passed function names"); |
|
|
|
for (i = 1; i < length; i++) { |
|
|
|
for (i = 1; i < length; i++) { |
|
|
|
key = arguments[i]; |
|
|
|
key = arguments[i]; |
|
|
|
obj[key] = _.bind(obj[key], obj); |
|
|
|
obj[key] = _.bind(obj[key], obj); |
|
|
@ -745,7 +745,7 @@ |
|
|
|
_.memoize = function (func, hasher) { |
|
|
|
_.memoize = function (func, hasher) { |
|
|
|
var memoize = function (key) { |
|
|
|
var memoize = function (key) { |
|
|
|
var cache = memoize.cache; |
|
|
|
var cache = memoize.cache; |
|
|
|
var address = '' + (hasher ? hasher.apply(this, arguments) : key); |
|
|
|
var address = "" + (hasher ? hasher.apply(this, arguments) : key); |
|
|
|
if (!_.has(cache, address)) cache[address] = func.apply(this, arguments); |
|
|
|
if (!_.has(cache, address)) cache[address] = func.apply(this, arguments); |
|
|
|
return cache[address]; |
|
|
|
return cache[address]; |
|
|
|
}; |
|
|
|
}; |
|
|
@ -895,9 +895,9 @@ |
|
|
|
// ----------------
|
|
|
|
// ----------------
|
|
|
|
|
|
|
|
|
|
|
|
// Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
|
|
|
|
// Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
|
|
|
|
var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString'); |
|
|
|
var hasEnumBug = !{toString: null}.propertyIsEnumerable("toString"); |
|
|
|
var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString', |
|
|
|
var nonEnumerableProps = ["valueOf", "isPrototypeOf", "toString", |
|
|
|
'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString']; |
|
|
|
"propertyIsEnumerable", "hasOwnProperty", "toLocaleString"]; |
|
|
|
|
|
|
|
|
|
|
|
function collectNonEnumProps (obj, keys) { |
|
|
|
function collectNonEnumProps (obj, keys) { |
|
|
|
var nonEnumIdx = nonEnumerableProps.length; |
|
|
|
var nonEnumIdx = nonEnumerableProps.length; |
|
|
@ -905,7 +905,7 @@ |
|
|
|
var proto = (_.isFunction(constructor) && constructor.prototype) || ObjProto; |
|
|
|
var proto = (_.isFunction(constructor) && constructor.prototype) || ObjProto; |
|
|
|
|
|
|
|
|
|
|
|
// Constructor is a special case.
|
|
|
|
// Constructor is a special case.
|
|
|
|
var prop = 'constructor'; |
|
|
|
var prop = "constructor"; |
|
|
|
if (_.has(obj, prop) && !_.contains(keys, prop)) keys.push(prop); |
|
|
|
if (_.has(obj, prop) && !_.contains(keys, prop)) keys.push(prop); |
|
|
|
|
|
|
|
|
|
|
|
while (nonEnumIdx--) { |
|
|
|
while (nonEnumIdx--) { |
|
|
@ -1099,36 +1099,36 @@ |
|
|
|
if (className !== toString.call(b)) return false; |
|
|
|
if (className !== toString.call(b)) return false; |
|
|
|
switch (className) { |
|
|
|
switch (className) { |
|
|
|
// Strings, numbers, regular expressions, dates, and booleans are compared by value.
|
|
|
|
// Strings, numbers, regular expressions, dates, and booleans are compared by value.
|
|
|
|
case '[object RegExp]': |
|
|
|
case "[object RegExp]": |
|
|
|
// RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
|
|
|
|
// RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
|
|
|
|
case '[object String]': |
|
|
|
case "[object String]": |
|
|
|
// Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
|
|
|
|
// Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
|
|
|
|
// equivalent to `new String("5")`.
|
|
|
|
// equivalent to `new String("5")`.
|
|
|
|
return '' + a === '' + b; |
|
|
|
return "" + a === "" + b; |
|
|
|
case '[object Number]': |
|
|
|
case "[object Number]": |
|
|
|
// `NaN`s are equivalent, but non-reflexive.
|
|
|
|
// `NaN`s are equivalent, but non-reflexive.
|
|
|
|
// Object(NaN) is equivalent to NaN
|
|
|
|
// Object(NaN) is equivalent to NaN
|
|
|
|
if (+a !== +a) return +b !== +b; |
|
|
|
if (+a !== +a) return +b !== +b; |
|
|
|
// An `egal` comparison is performed for other numeric values.
|
|
|
|
// An `egal` comparison is performed for other numeric values.
|
|
|
|
return +a === 0 ? 1 / +a === 1 / b : +a === +b; |
|
|
|
return +a === 0 ? 1 / +a === 1 / b : +a === +b; |
|
|
|
case '[object Date]': |
|
|
|
case "[object Date]": |
|
|
|
case '[object Boolean]': |
|
|
|
case "[object Boolean]": |
|
|
|
// Coerce dates and booleans to numeric primitive values. Dates are compared by their
|
|
|
|
// Coerce dates and booleans to numeric primitive values. Dates are compared by their
|
|
|
|
// millisecond representations. Note that invalid dates with millisecond representations
|
|
|
|
// millisecond representations. Note that invalid dates with millisecond representations
|
|
|
|
// of `NaN` are not equivalent.
|
|
|
|
// of `NaN` are not equivalent.
|
|
|
|
return +a === +b; |
|
|
|
return +a === +b; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var areArrays = className === '[object Array]'; |
|
|
|
var areArrays = className === "[object Array]"; |
|
|
|
if (!areArrays) { |
|
|
|
if (!areArrays) { |
|
|
|
if (typeof a != 'object' || typeof b != 'object') return false; |
|
|
|
if (typeof a !== "object" || typeof b !== "object") return false; |
|
|
|
|
|
|
|
|
|
|
|
// Objects with different constructors are not equivalent, but `Object`s or `Array`s
|
|
|
|
// Objects with different constructors are not equivalent, but `Object`s or `Array`s
|
|
|
|
// from different frames are.
|
|
|
|
// from different frames are.
|
|
|
|
var aCtor = a.constructor, bCtor = b.constructor; |
|
|
|
var aCtor = a.constructor, bCtor = b.constructor; |
|
|
|
if (aCtor !== bCtor && !(_.isFunction(aCtor) && aCtor instanceof aCtor && |
|
|
|
if (aCtor !== bCtor && !(_.isFunction(aCtor) && aCtor instanceof aCtor && |
|
|
|
_.isFunction(bCtor) && bCtor instanceof bCtor) |
|
|
|
_.isFunction(bCtor) && bCtor instanceof bCtor) |
|
|
|
&& ('constructor' in a && 'constructor' in b)) { |
|
|
|
&& ("constructor" in a && "constructor" in b)) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1198,19 +1198,19 @@ |
|
|
|
// Is a given value an array?
|
|
|
|
// Is a given value an array?
|
|
|
|
// Delegates to ECMA5's native Array.isArray
|
|
|
|
// Delegates to ECMA5's native Array.isArray
|
|
|
|
_.isArray = nativeIsArray || function (obj) { |
|
|
|
_.isArray = nativeIsArray || function (obj) { |
|
|
|
return toString.call(obj) === '[object Array]'; |
|
|
|
return toString.call(obj) === "[object Array]"; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Is a given variable an object?
|
|
|
|
// Is a given variable an object?
|
|
|
|
_.isObject = function (obj) { |
|
|
|
_.isObject = function (obj) { |
|
|
|
var type = typeof obj; |
|
|
|
var type = typeof obj; |
|
|
|
return type === 'function' || type === 'object' && !!obj; |
|
|
|
return type === "function" || type === "object" && !!obj; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError.
|
|
|
|
// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError.
|
|
|
|
_.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error'], function(name) { |
|
|
|
_.each(["Arguments", "Function", "String", "Number", "Date", "RegExp", "Error"], function (name) { |
|
|
|
_['is' + name] = function(obj) { |
|
|
|
_["is" + name] = function (obj) { |
|
|
|
return toString.call(obj) === '[object ' + name + ']'; |
|
|
|
return toString.call(obj) === "[object " + name + "]"; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -1218,15 +1218,15 @@ |
|
|
|
// there isn't any inspectable "Arguments" type.
|
|
|
|
// there isn't any inspectable "Arguments" type.
|
|
|
|
if (!_.isArguments(arguments)) { |
|
|
|
if (!_.isArguments(arguments)) { |
|
|
|
_.isArguments = function (obj) { |
|
|
|
_.isArguments = function (obj) { |
|
|
|
return _.has(obj, 'callee'); |
|
|
|
return _.has(obj, "callee"); |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Optimize `isFunction` if appropriate. Work around some typeof bugs in old v8,
|
|
|
|
// Optimize `isFunction` if appropriate. Work around some typeof bugs in old v8,
|
|
|
|
// IE 11 (#1621), and in Safari 8 (#1929).
|
|
|
|
// IE 11 (#1621), and in Safari 8 (#1929).
|
|
|
|
if (typeof /./ != 'function' && typeof Int8Array != 'object') { |
|
|
|
if (typeof /./ !== "function" && typeof Int8Array !== "object") { |
|
|
|
_.isFunction = function (obj) { |
|
|
|
_.isFunction = function (obj) { |
|
|
|
return typeof obj == 'function' || false; |
|
|
|
return typeof obj === "function" || false; |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1242,7 +1242,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
// Is a given value a boolean?
|
|
|
|
// Is a given value a boolean?
|
|
|
|
_.isBoolean = function (obj) { |
|
|
|
_.isBoolean = function (obj) { |
|
|
|
return obj === true || obj === false || toString.call(obj) === '[object Boolean]'; |
|
|
|
return obj === true || obj === false || toString.call(obj) === "[object Boolean]"; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Is a given value equal to null?
|
|
|
|
// Is a given value equal to null?
|
|
|
@ -1331,12 +1331,12 @@ |
|
|
|
|
|
|
|
|
|
|
|
// List of HTML entities for escaping.
|
|
|
|
// List of HTML entities for escaping.
|
|
|
|
var escapeMap = { |
|
|
|
var escapeMap = { |
|
|
|
'&': '&', |
|
|
|
"&": "&", |
|
|
|
'<': '<', |
|
|
|
"<": "<", |
|
|
|
'>': '>', |
|
|
|
">": ">", |
|
|
|
'"': '"', |
|
|
|
"\"": """, |
|
|
|
"'": ''', |
|
|
|
"'": "'", |
|
|
|
'`': '`' |
|
|
|
"`": "`" |
|
|
|
}; |
|
|
|
}; |
|
|
|
var unescapeMap = _.invert(escapeMap); |
|
|
|
var unescapeMap = _.invert(escapeMap); |
|
|
|
|
|
|
|
|
|
|
@ -1346,11 +1346,11 @@ |
|
|
|
return map[match]; |
|
|
|
return map[match]; |
|
|
|
}; |
|
|
|
}; |
|
|
|
// Regexes for identifying a key that needs to be escaped
|
|
|
|
// Regexes for identifying a key that needs to be escaped
|
|
|
|
var source = '(?:' + _.keys(map).join('|') + ')'; |
|
|
|
var source = "(?:" + _.keys(map).join("|") + ")"; |
|
|
|
var testRegexp = RegExp(source); |
|
|
|
var testRegexp = RegExp(source); |
|
|
|
var replaceRegexp = RegExp(source, 'g'); |
|
|
|
var replaceRegexp = RegExp(source, "g"); |
|
|
|
return function (string) { |
|
|
|
return function (string) { |
|
|
|
string = string == null ? '' : '' + string; |
|
|
|
string = string == null ? "" : "" + string; |
|
|
|
return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string; |
|
|
|
return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
@ -1371,7 +1371,7 @@ |
|
|
|
// Useful for temporary DOM ids.
|
|
|
|
// Useful for temporary DOM ids.
|
|
|
|
var idCounter = 0; |
|
|
|
var idCounter = 0; |
|
|
|
_.uniqueId = function (prefix) { |
|
|
|
_.uniqueId = function (prefix) { |
|
|
|
var id = ++idCounter + ''; |
|
|
|
var id = ++idCounter + ""; |
|
|
|
return prefix ? prefix + id : id; |
|
|
|
return prefix ? prefix + id : id; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -1392,17 +1392,17 @@ |
|
|
|
// string literal.
|
|
|
|
// string literal.
|
|
|
|
var escapes = { |
|
|
|
var escapes = { |
|
|
|
"'": "'", |
|
|
|
"'": "'", |
|
|
|
'\\': '\\', |
|
|
|
"\\": "\\", |
|
|
|
'\r': 'r', |
|
|
|
"\r": "r", |
|
|
|
'\n': 'n', |
|
|
|
"\n": "n", |
|
|
|
'\u2028': 'u2028', |
|
|
|
"\u2028": "u2028", |
|
|
|
'\u2029': 'u2029' |
|
|
|
"\u2029": "u2029" |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var escaper = /\\|'|\r|\n|\u2028|\u2029/g; |
|
|
|
var escaper = /\\|'|\r|\n|\u2028|\u2029/g; |
|
|
|
|
|
|
|
|
|
|
|
var escapeChar = function (match) { |
|
|
|
var escapeChar = function (match) { |
|
|
|
return '\\' + escapes[match]; |
|
|
|
return "\\" + escapes[match]; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// JavaScript micro-templating, similar to John Resig's implementation.
|
|
|
|
// JavaScript micro-templating, similar to John Resig's implementation.
|
|
|
@ -1418,7 +1418,7 @@ |
|
|
|
(settings.escape || noMatch).source, |
|
|
|
(settings.escape || noMatch).source, |
|
|
|
(settings.interpolate || noMatch).source, |
|
|
|
(settings.interpolate || noMatch).source, |
|
|
|
(settings.evaluate || noMatch).source |
|
|
|
(settings.evaluate || noMatch).source |
|
|
|
].join('|') + '|$', 'g'); |
|
|
|
].join("|") + "|$", "g"); |
|
|
|
|
|
|
|
|
|
|
|
// Compile the template source, escaping string literals appropriately.
|
|
|
|
// Compile the template source, escaping string literals appropriately.
|
|
|
|
var index = 0; |
|
|
|
var index = 0; |
|
|
@ -1441,14 +1441,14 @@ |
|
|
|
source += "';\n"; |
|
|
|
source += "';\n"; |
|
|
|
|
|
|
|
|
|
|
|
// If a variable is not specified, place data values in local scope.
|
|
|
|
// If a variable is not specified, place data values in local scope.
|
|
|
|
if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; |
|
|
|
if (!settings.variable) source = "with(obj||{}){\n" + source + "}\n"; |
|
|
|
|
|
|
|
|
|
|
|
source = "var __t,__p='',__j=Array.prototype.join," + |
|
|
|
source = "var __t,__p='',__j=Array.prototype.join," + |
|
|
|
"print=function(){__p+=__j.call(arguments,'');};\n" + |
|
|
|
"print=function(){__p+=__j.call(arguments,'');};\n" + |
|
|
|
source + 'return __p;\n'; |
|
|
|
source + "return __p;\n"; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
var render = new Function(settings.variable || 'obj', '_', source); |
|
|
|
var render = new Function(settings.variable || "obj", "_", source); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
e.source = source; |
|
|
|
e.source = source; |
|
|
|
throw e; |
|
|
|
throw e; |
|
|
@ -1459,8 +1459,8 @@ |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Provide the compiled source as a convenience for precompilation.
|
|
|
|
// Provide the compiled source as a convenience for precompilation.
|
|
|
|
var argument = settings.variable || 'obj'; |
|
|
|
var argument = settings.variable || "obj"; |
|
|
|
template.source = 'function(' + argument + '){\n' + source + '}'; |
|
|
|
template.source = "function(" + argument + "){\n" + source + "}"; |
|
|
|
|
|
|
|
|
|
|
|
return template; |
|
|
|
return template; |
|
|
|
}; |
|
|
|
}; |
|
|
@ -1499,18 +1499,18 @@ |
|
|
|
_.mixin(_); |
|
|
|
_.mixin(_); |
|
|
|
|
|
|
|
|
|
|
|
// Add all mutator Array functions to the wrapper.
|
|
|
|
// Add all mutator Array functions to the wrapper.
|
|
|
|
_.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { |
|
|
|
_.each(["pop", "push", "reverse", "shift", "sort", "splice", "unshift"], function (name) { |
|
|
|
var method = ArrayProto[name]; |
|
|
|
var method = ArrayProto[name]; |
|
|
|
_.prototype[name] = function () { |
|
|
|
_.prototype[name] = function () { |
|
|
|
var obj = this._wrapped; |
|
|
|
var obj = this._wrapped; |
|
|
|
method.apply(obj, arguments); |
|
|
|
method.apply(obj, arguments); |
|
|
|
if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0]; |
|
|
|
if ((name === "shift" || name === "splice") && obj.length === 0) delete obj[0]; |
|
|
|
return result(this, obj); |
|
|
|
return result(this, obj); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Add all accessor Array functions to the wrapper.
|
|
|
|
// Add all accessor Array functions to the wrapper.
|
|
|
|
_.each(['concat', 'join', 'slice'], function(name) { |
|
|
|
_.each(["concat", "join", "slice"], function (name) { |
|
|
|
var method = ArrayProto[name]; |
|
|
|
var method = ArrayProto[name]; |
|
|
|
_.prototype[name] = function () { |
|
|
|
_.prototype[name] = function () { |
|
|
|
return result(this, method.apply(this._wrapped, arguments)); |
|
|
|
return result(this, method.apply(this._wrapped, arguments)); |
|
|
@ -1527,7 +1527,7 @@ |
|
|
|
_.prototype.valueOf = _.prototype.toJSON = _.prototype.value; |
|
|
|
_.prototype.valueOf = _.prototype.toJSON = _.prototype.value; |
|
|
|
|
|
|
|
|
|
|
|
_.prototype.toString = function () { |
|
|
|
_.prototype.toString = function () { |
|
|
|
return '' + this._wrapped; |
|
|
|
return "" + this._wrapped; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// AMD registration happens at the end for compatibility with AMD loaders
|
|
|
|
// AMD registration happens at the end for compatibility with AMD loaders
|
|
|
@ -1537,8 +1537,8 @@ |
|
|
|
// popular enough to be bundled in a third party lib, but not be part of
|
|
|
|
// popular enough to be bundled in a third party lib, but not be part of
|
|
|
|
// an AMD load request. Those cases could generate an error when an
|
|
|
|
// an AMD load request. Those cases could generate an error when an
|
|
|
|
// anonymous define() is called outside of a loader request.
|
|
|
|
// anonymous define() is called outside of a loader request.
|
|
|
|
if (typeof define === 'function' && define.amd) { |
|
|
|
if (typeof define === "function" && define.amd) { |
|
|
|
define('underscore', [], function() { |
|
|
|
define("underscore", [], function () { |
|
|
|
return _; |
|
|
|
return _; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|