mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Avoid Array.prototype issues in Narwhal.
Former-commit-id: 47627a187d59fb83f4a5b84b03158432d5216395
This commit is contained in:
16
build.js
16
build.js
@@ -18,10 +18,10 @@
|
|||||||
var cwd = process.cwd();
|
var cwd = process.cwd();
|
||||||
|
|
||||||
/** Used for array method references */
|
/** Used for array method references */
|
||||||
var arrayProto = Array.prototype;
|
var arrayRef = Array.prototype;
|
||||||
|
|
||||||
/** Shortcut used to push arrays of values to an array */
|
/** Shortcut used to push arrays of values to an array */
|
||||||
var push = arrayProto.push;
|
var push = arrayRef.push;
|
||||||
|
|
||||||
/** Used to create regexes that may detect multi-line comment blocks */
|
/** Used to create regexes that may detect multi-line comment blocks */
|
||||||
var multilineComment = '(?:\\n +/\\*[^*]*\\*+(?:[^/][^*]*\\*+)*/)?\\n';
|
var multilineComment = '(?:\\n +/\\*[^*]*\\*+(?:[^/][^*]*\\*+)*/)?\\n';
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
var reNode = RegExp('(?:^|' + path.sepEscaped + ')node(?:\\.exe)?$');
|
var reNode = RegExp('(?:^|' + path.sepEscaped + ')node(?:\\.exe)?$');
|
||||||
|
|
||||||
/** Shortcut used to convert array-like objects to arrays */
|
/** Shortcut used to convert array-like objects to arrays */
|
||||||
var slice = arrayProto.slice;
|
var slice = arrayRef.slice;
|
||||||
|
|
||||||
/** Shortcut to the `stdout` object */
|
/** Shortcut to the `stdout` object */
|
||||||
var stdout = process.stdout;
|
var stdout = process.stdout;
|
||||||
@@ -470,7 +470,7 @@
|
|||||||
return indent + [
|
return indent + [
|
||||||
'// add `Array` mutator functions to the wrapper',
|
'// add `Array` mutator functions to the wrapper',
|
||||||
funcName + "(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {",
|
funcName + "(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {",
|
||||||
' var func = arrayProto[methodName];',
|
' var func = arrayRef[methodName];',
|
||||||
' lodash.prototype[methodName] = function() {',
|
' lodash.prototype[methodName] = function() {',
|
||||||
' var value = this.__wrapped__;',
|
' var value = this.__wrapped__;',
|
||||||
' func.apply(value, arguments);',
|
' func.apply(value, arguments);',
|
||||||
@@ -486,7 +486,7 @@
|
|||||||
'',
|
'',
|
||||||
'// add `Array` accessor functions to the wrapper',
|
'// add `Array` accessor functions to the wrapper',
|
||||||
funcName + "(['concat', 'join', 'slice'], function(methodName) {",
|
funcName + "(['concat', 'join', 'slice'], function(methodName) {",
|
||||||
' var func = arrayProto[methodName];',
|
' var func = arrayRef[methodName];',
|
||||||
' lodash.prototype[methodName] = function() {',
|
' lodash.prototype[methodName] = function() {',
|
||||||
' var value = this.__wrapped__,',
|
' var value = this.__wrapped__,',
|
||||||
' result = func.apply(value, arguments);',
|
' result = func.apply(value, arguments);',
|
||||||
@@ -2434,7 +2434,7 @@
|
|||||||
' var index = -1,',
|
' var index = -1,',
|
||||||
' indexOf = getIndexOf(),',
|
' indexOf = getIndexOf(),',
|
||||||
' length = array.length,',
|
' length = array.length,',
|
||||||
' flattened = concat.apply(arrayProto, nativeSlice.call(arguments, 1)),',
|
' flattened = concat.apply(arrayRef, nativeSlice.call(arguments, 1)),',
|
||||||
' result = [];',
|
' result = [];',
|
||||||
'',
|
'',
|
||||||
' while (++index < length) {',
|
' while (++index < length) {',
|
||||||
@@ -2676,7 +2676,7 @@
|
|||||||
source = replaceFunction(source, 'omit', [
|
source = replaceFunction(source, 'omit', [
|
||||||
'function omit(object) {',
|
'function omit(object) {',
|
||||||
' var indexOf = getIndexOf(),',
|
' var indexOf = getIndexOf(),',
|
||||||
' props = concat.apply(arrayProto, nativeSlice.call(arguments, 1)),',
|
' props = concat.apply(arrayRef, nativeSlice.call(arguments, 1)),',
|
||||||
' result = {};',
|
' result = {};',
|
||||||
'',
|
'',
|
||||||
' forIn(object, function(value, key) {',
|
' forIn(object, function(value, key) {',
|
||||||
@@ -2693,7 +2693,7 @@
|
|||||||
source = replaceFunction(source, 'pick', [
|
source = replaceFunction(source, 'pick', [
|
||||||
'function pick(object) {',
|
'function pick(object) {',
|
||||||
' var index = -1,',
|
' var index = -1,',
|
||||||
' props = concat.apply(arrayProto, nativeSlice.call(arguments, 1)),',
|
' props = concat.apply(arrayRef, nativeSlice.call(arguments, 1)),',
|
||||||
' length = props.length,',
|
' length = props.length,',
|
||||||
' result = {};',
|
' result = {};',
|
||||||
'',
|
'',
|
||||||
|
|||||||
43
lodash.js
43
lodash.js
@@ -465,9 +465,16 @@
|
|||||||
String = context.String,
|
String = context.String,
|
||||||
TypeError = context.TypeError;
|
TypeError = context.TypeError;
|
||||||
|
|
||||||
/** Used for `Array` and `Object` method references */
|
/**
|
||||||
var arrayProto = Array.prototype,
|
* Used for `Array` method references.
|
||||||
errorProto = Error.prototype,
|
*
|
||||||
|
* Normally `Array.prototype` would suffice, however, using an array literal
|
||||||
|
* avoids issues in Narwhal.
|
||||||
|
*/
|
||||||
|
var arrayRef = [];
|
||||||
|
|
||||||
|
/** Used for native method references */
|
||||||
|
var errorProto = Error.prototype,
|
||||||
objectProto = Object.prototype,
|
objectProto = Object.prototype,
|
||||||
stringProto = String.prototype;
|
stringProto = String.prototype;
|
||||||
|
|
||||||
@@ -484,12 +491,12 @@
|
|||||||
/** Native method shortcuts */
|
/** Native method shortcuts */
|
||||||
var ceil = Math.ceil,
|
var ceil = Math.ceil,
|
||||||
clearTimeout = context.clearTimeout,
|
clearTimeout = context.clearTimeout,
|
||||||
concat = arrayProto.concat,
|
concat = arrayRef.concat,
|
||||||
floor = Math.floor,
|
floor = Math.floor,
|
||||||
fnToString = Function.prototype.toString,
|
fnToString = Function.prototype.toString,
|
||||||
getPrototypeOf = reNative.test(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
|
getPrototypeOf = reNative.test(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
|
||||||
hasOwnProperty = objectProto.hasOwnProperty,
|
hasOwnProperty = objectProto.hasOwnProperty,
|
||||||
push = arrayProto.push,
|
push = arrayRef.push,
|
||||||
propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
||||||
setImmediate = context.setImmediate,
|
setImmediate = context.setImmediate,
|
||||||
setTimeout = context.setTimeout,
|
setTimeout = context.setTimeout,
|
||||||
@@ -506,7 +513,7 @@
|
|||||||
nativeMin = Math.min,
|
nativeMin = Math.min,
|
||||||
nativeParseInt = context.parseInt,
|
nativeParseInt = context.parseInt,
|
||||||
nativeRandom = Math.random,
|
nativeRandom = Math.random,
|
||||||
nativeSlice = arrayProto.slice;
|
nativeSlice = arrayRef.slice;
|
||||||
|
|
||||||
/** Detect various environments */
|
/** Detect various environments */
|
||||||
var isIeOpera = reNative.test(context.attachEvent),
|
var isIeOpera = reNative.test(context.attachEvent),
|
||||||
@@ -729,7 +736,7 @@
|
|||||||
* @memberOf _.support
|
* @memberOf _.support
|
||||||
* @type Boolean
|
* @type Boolean
|
||||||
*/
|
*/
|
||||||
support.spliceObjects = (arrayProto.splice.call(object, 0, 1), !object[0]);
|
support.spliceObjects = (arrayRef.splice.call(object, 0, 1), !object[0]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect lack of support for accessing string characters by index.
|
* Detect lack of support for accessing string characters by index.
|
||||||
@@ -2426,7 +2433,7 @@
|
|||||||
if (isFunc) {
|
if (isFunc) {
|
||||||
callback = lodash.createCallback(callback, thisArg);
|
callback = lodash.createCallback(callback, thisArg);
|
||||||
} else {
|
} else {
|
||||||
var props = concat.apply(arrayProto, nativeSlice.call(arguments, 1));
|
var props = concat.apply(arrayRef, nativeSlice.call(arguments, 1));
|
||||||
}
|
}
|
||||||
forIn(object, function(value, key, object) {
|
forIn(object, function(value, key, object) {
|
||||||
if (isFunc
|
if (isFunc
|
||||||
@@ -2495,7 +2502,7 @@
|
|||||||
var result = {};
|
var result = {};
|
||||||
if (typeof callback != 'function') {
|
if (typeof callback != 'function') {
|
||||||
var index = -1,
|
var index = -1,
|
||||||
props = concat.apply(arrayProto, nativeSlice.call(arguments, 1)),
|
props = concat.apply(arrayRef, nativeSlice.call(arguments, 1)),
|
||||||
length = isObject(object) ? props.length : 0;
|
length = isObject(object) ? props.length : 0;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
@@ -2616,7 +2623,7 @@
|
|||||||
*/
|
*/
|
||||||
function at(collection) {
|
function at(collection) {
|
||||||
var index = -1,
|
var index = -1,
|
||||||
props = concat.apply(arrayProto, nativeSlice.call(arguments, 1)),
|
props = concat.apply(arrayRef, nativeSlice.call(arguments, 1)),
|
||||||
length = props.length,
|
length = props.length,
|
||||||
result = Array(length);
|
result = Array(length);
|
||||||
|
|
||||||
@@ -3661,7 +3668,7 @@
|
|||||||
var index = -1,
|
var index = -1,
|
||||||
indexOf = getIndexOf(),
|
indexOf = getIndexOf(),
|
||||||
length = array ? array.length : 0,
|
length = array ? array.length : 0,
|
||||||
seen = concat.apply(arrayProto, nativeSlice.call(arguments, 1)),
|
seen = concat.apply(arrayRef, nativeSlice.call(arguments, 1)),
|
||||||
result = [];
|
result = [];
|
||||||
|
|
||||||
var isLarge = length >= largeArraySize && indexOf === basicIndexOf;
|
var isLarge = length >= largeArraySize && indexOf === basicIndexOf;
|
||||||
@@ -4345,9 +4352,9 @@
|
|||||||
*/
|
*/
|
||||||
function union(array) {
|
function union(array) {
|
||||||
if (!isArray(array)) {
|
if (!isArray(array)) {
|
||||||
arguments[0] = array ? nativeSlice.call(array) : arrayProto;
|
arguments[0] = array ? nativeSlice.call(array) : arrayRef;
|
||||||
}
|
}
|
||||||
return uniq(concat.apply(arrayProto, arguments));
|
return uniq(concat.apply(arrayRef, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -4622,7 +4629,7 @@
|
|||||||
* // => alerts 'clicked docs', when the button is clicked
|
* // => alerts 'clicked docs', when the button is clicked
|
||||||
*/
|
*/
|
||||||
function bindAll(object) {
|
function bindAll(object) {
|
||||||
var funcs = arguments.length > 1 ? concat.apply(arrayProto, nativeSlice.call(arguments, 1)) : functions(object),
|
var funcs = arguments.length > 1 ? concat.apply(arrayRef, nativeSlice.call(arguments, 1)) : functions(object),
|
||||||
index = -1,
|
index = -1,
|
||||||
length = funcs.length;
|
length = funcs.length;
|
||||||
|
|
||||||
@@ -5828,7 +5835,7 @@
|
|||||||
|
|
||||||
// add `Array` functions that return unwrapped values
|
// add `Array` functions that return unwrapped values
|
||||||
basicEach(['join', 'pop', 'shift'], function(methodName) {
|
basicEach(['join', 'pop', 'shift'], function(methodName) {
|
||||||
var func = arrayProto[methodName];
|
var func = arrayRef[methodName];
|
||||||
lodash.prototype[methodName] = function() {
|
lodash.prototype[methodName] = function() {
|
||||||
return func.apply(this.__wrapped__, arguments);
|
return func.apply(this.__wrapped__, arguments);
|
||||||
};
|
};
|
||||||
@@ -5836,7 +5843,7 @@
|
|||||||
|
|
||||||
// add `Array` functions that return the wrapped value
|
// add `Array` functions that return the wrapped value
|
||||||
basicEach(['push', 'reverse', 'sort', 'unshift'], function(methodName) {
|
basicEach(['push', 'reverse', 'sort', 'unshift'], function(methodName) {
|
||||||
var func = arrayProto[methodName];
|
var func = arrayRef[methodName];
|
||||||
lodash.prototype[methodName] = function() {
|
lodash.prototype[methodName] = function() {
|
||||||
func.apply(this.__wrapped__, arguments);
|
func.apply(this.__wrapped__, arguments);
|
||||||
return this;
|
return this;
|
||||||
@@ -5845,7 +5852,7 @@
|
|||||||
|
|
||||||
// add `Array` functions that return new wrapped values
|
// add `Array` functions that return new wrapped values
|
||||||
basicEach(['concat', 'slice', 'splice'], function(methodName) {
|
basicEach(['concat', 'slice', 'splice'], function(methodName) {
|
||||||
var func = arrayProto[methodName];
|
var func = arrayRef[methodName];
|
||||||
lodash.prototype[methodName] = function() {
|
lodash.prototype[methodName] = function() {
|
||||||
return new lodashWrapper(func.apply(this.__wrapped__, arguments));
|
return new lodashWrapper(func.apply(this.__wrapped__, arguments));
|
||||||
};
|
};
|
||||||
@@ -5855,7 +5862,7 @@
|
|||||||
// in Firefox < 10 and IE < 9
|
// in Firefox < 10 and IE < 9
|
||||||
if (!support.spliceObjects) {
|
if (!support.spliceObjects) {
|
||||||
basicEach(['pop', 'shift', 'splice'], function(methodName) {
|
basicEach(['pop', 'shift', 'splice'], function(methodName) {
|
||||||
var func = arrayProto[methodName],
|
var func = arrayRef[methodName],
|
||||||
isSplice = methodName == 'splice';
|
isSplice = methodName == 'splice';
|
||||||
|
|
||||||
lodash.prototype[methodName] = function() {
|
lodash.prototype[methodName] = function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user