diff --git a/build.js b/build.js index 3909ebcac..c9dc07335 100755 --- a/build.js +++ b/build.js @@ -18,10 +18,10 @@ var cwd = process.cwd(); /** Used for array method references */ - var arrayProto = Array.prototype; + var arrayRef = Array.prototype; /** 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 */ var multilineComment = '(?:\\n +/\\*[^*]*\\*+(?:[^/][^*]*\\*+)*/)?\\n'; @@ -30,7 +30,7 @@ var reNode = RegExp('(?:^|' + path.sepEscaped + ')node(?:\\.exe)?$'); /** Shortcut used to convert array-like objects to arrays */ - var slice = arrayProto.slice; + var slice = arrayRef.slice; /** Shortcut to the `stdout` object */ var stdout = process.stdout; @@ -470,7 +470,7 @@ return indent + [ '// add `Array` mutator functions to the wrapper', funcName + "(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {", - ' var func = arrayProto[methodName];', + ' var func = arrayRef[methodName];', ' lodash.prototype[methodName] = function() {', ' var value = this.__wrapped__;', ' func.apply(value, arguments);', @@ -486,7 +486,7 @@ '', '// add `Array` accessor functions to the wrapper', funcName + "(['concat', 'join', 'slice'], function(methodName) {", - ' var func = arrayProto[methodName];', + ' var func = arrayRef[methodName];', ' lodash.prototype[methodName] = function() {', ' var value = this.__wrapped__,', ' result = func.apply(value, arguments);', @@ -2434,7 +2434,7 @@ ' var index = -1,', ' indexOf = getIndexOf(),', ' length = array.length,', - ' flattened = concat.apply(arrayProto, nativeSlice.call(arguments, 1)),', + ' flattened = concat.apply(arrayRef, nativeSlice.call(arguments, 1)),', ' result = [];', '', ' while (++index < length) {', @@ -2676,7 +2676,7 @@ source = replaceFunction(source, 'omit', [ 'function omit(object) {', ' var indexOf = getIndexOf(),', - ' props = concat.apply(arrayProto, nativeSlice.call(arguments, 1)),', + ' props = concat.apply(arrayRef, nativeSlice.call(arguments, 1)),', ' result = {};', '', ' forIn(object, function(value, key) {', @@ -2693,7 +2693,7 @@ source = replaceFunction(source, 'pick', [ 'function pick(object) {', ' var index = -1,', - ' props = concat.apply(arrayProto, nativeSlice.call(arguments, 1)),', + ' props = concat.apply(arrayRef, nativeSlice.call(arguments, 1)),', ' length = props.length,', ' result = {};', '', diff --git a/lodash.js b/lodash.js index be0e8f7c7..e84a60674 100644 --- a/lodash.js +++ b/lodash.js @@ -465,9 +465,16 @@ String = context.String, TypeError = context.TypeError; - /** Used for `Array` and `Object` method references */ - var arrayProto = Array.prototype, - errorProto = Error.prototype, + /** + * Used for `Array` method references. + * + * 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, stringProto = String.prototype; @@ -484,12 +491,12 @@ /** Native method shortcuts */ var ceil = Math.ceil, clearTimeout = context.clearTimeout, - concat = arrayProto.concat, + concat = arrayRef.concat, floor = Math.floor, fnToString = Function.prototype.toString, getPrototypeOf = reNative.test(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf, hasOwnProperty = objectProto.hasOwnProperty, - push = arrayProto.push, + push = arrayRef.push, propertyIsEnumerable = objectProto.propertyIsEnumerable, setImmediate = context.setImmediate, setTimeout = context.setTimeout, @@ -506,7 +513,7 @@ nativeMin = Math.min, nativeParseInt = context.parseInt, nativeRandom = Math.random, - nativeSlice = arrayProto.slice; + nativeSlice = arrayRef.slice; /** Detect various environments */ var isIeOpera = reNative.test(context.attachEvent), @@ -729,7 +736,7 @@ * @memberOf _.support * @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. @@ -2426,7 +2433,7 @@ if (isFunc) { callback = lodash.createCallback(callback, thisArg); } 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) { if (isFunc @@ -2495,7 +2502,7 @@ var result = {}; if (typeof callback != 'function') { 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; while (++index < length) { @@ -2616,7 +2623,7 @@ */ function at(collection) { var index = -1, - props = concat.apply(arrayProto, nativeSlice.call(arguments, 1)), + props = concat.apply(arrayRef, nativeSlice.call(arguments, 1)), length = props.length, result = Array(length); @@ -3661,7 +3668,7 @@ var index = -1, indexOf = getIndexOf(), length = array ? array.length : 0, - seen = concat.apply(arrayProto, nativeSlice.call(arguments, 1)), + seen = concat.apply(arrayRef, nativeSlice.call(arguments, 1)), result = []; var isLarge = length >= largeArraySize && indexOf === basicIndexOf; @@ -4345,9 +4352,9 @@ */ function union(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 */ 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, length = funcs.length; @@ -5828,7 +5835,7 @@ // add `Array` functions that return unwrapped values basicEach(['join', 'pop', 'shift'], function(methodName) { - var func = arrayProto[methodName]; + var func = arrayRef[methodName]; lodash.prototype[methodName] = function() { return func.apply(this.__wrapped__, arguments); }; @@ -5836,7 +5843,7 @@ // add `Array` functions that return the wrapped value basicEach(['push', 'reverse', 'sort', 'unshift'], function(methodName) { - var func = arrayProto[methodName]; + var func = arrayRef[methodName]; lodash.prototype[methodName] = function() { func.apply(this.__wrapped__, arguments); return this; @@ -5845,7 +5852,7 @@ // add `Array` functions that return new wrapped values basicEach(['concat', 'slice', 'splice'], function(methodName) { - var func = arrayProto[methodName]; + var func = arrayRef[methodName]; lodash.prototype[methodName] = function() { return new lodashWrapper(func.apply(this.__wrapped__, arguments)); }; @@ -5855,7 +5862,7 @@ // in Firefox < 10 and IE < 9 if (!support.spliceObjects) { basicEach(['pop', 'shift', 'splice'], function(methodName) { - var func = arrayProto[methodName], + var func = arrayRef[methodName], isSplice = methodName == 'splice'; lodash.prototype[methodName] = function() {