diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 285d6fd00..5fd66c455 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -1180,6 +1180,62 @@ return bind(func, thisArg); } + /** + * The base implementation of `createWrapper` without `func` type checking + * or support for setting meta data. + * + * @private + * @param {Function|string} func The function or method name to reference. + * @param {number} bitmask The bitmask of method flags to compose. + * @param {Array} [partialArgs] An array of arguments to prepend to those + * provided to the new function. + * @param {Array} [partialRightArgs] An array of arguments to append to those + * provided to the new function. + * @param {*} [thisArg] The `this` binding of `func`. + * @param {number} [arity] The arity of `func`. + * @returns {Function} Returns the new function. + */ + function baseCreateWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { + var isBind = bitmask & 1, + isBindKey = bitmask & 2, + isCurry = bitmask & 4, + isCurryBound = bitmask & 8, + isPartial = bitmask & 16, + isPartialRight = bitmask & 32, + key = func; + + function bound() { + var thisBinding = isBind ? thisArg : this; + if (isCurry || isPartial || isPartialRight) { + if (isPartial) { + var args = partialArgs.slice(); + push.apply(args, arguments); + } + if (isPartialRight || isCurry) { + args || (args = slice(arguments)); + if (isPartialRight) { + push.apply(args, partialRightArgs); + } + if (isCurry && args.length < arity) { + bitmask |= 16 & ~32; + return createWrapper(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity); + } + } + } + args || (args = arguments); + if (isBindKey) { + func = thisBinding[key]; + } + if (this instanceof bound) { + thisBinding = baseCreate(func.prototype); + var result = func.apply(thisBinding, args); + return isObject(result) ? result : thisBinding; + } + return func.apply(thisBinding, args); + } + return bound; + } + /** * The base implementation of `_.flatten` without support for callback * shorthands or `thisArg` binding. @@ -1571,16 +1627,15 @@ * provided to the new function. * @param {*} [thisArg] The `this` binding of `func`. * @param {number} [arity] The arity of `func`. - * @returns {Function} Returns the new bound function. + * @returns {Function} Returns the new function. */ - function createBound(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { + function createWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) { var isBind = bitmask & 1, isBindKey = bitmask & 2, isCurry = bitmask & 4, isCurryBound = bitmask & 8, isPartial = bitmask & 16, - isPartialRight = bitmask & 32, - key = func; + isPartialRight = bitmask & 32; if (!isBindKey && !isFunction(func)) { throw new TypeError; @@ -1619,45 +1674,15 @@ } // merge flags bindData[1] |= bitmask; - return createBound.apply(null, bindData); + return createWrapper.apply(null, bindData); } // fast path for `_.bind` - if (bitmask == 1 || bitmask === 17) { - var bound = baseBind(func, thisArg, partialArgs); - } - else { - bound = function() { - var thisBinding = isBind ? thisArg : this; - if (isCurry || isPartial || isPartialRight) { - if (isPartial) { - var args = partialArgs.slice(); - push.apply(args, arguments); - } - if (isPartialRight || isCurry) { - args || (args = slice(arguments)); - if (isPartialRight) { - push.apply(args, partialRightArgs); - } - if (isCurry && args.length < arity) { - bitmask |= 16 & ~32; - return createBound(func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity); - } - } - } - args || (args = arguments); - if (isBindKey) { - func = thisBinding[key]; - } - if (this instanceof bound) { - thisBinding = baseCreate(func.prototype); - var result = func.apply(thisBinding, args); - return isObject(result) ? result : thisBinding; - } - return func.apply(thisBinding, args); - }; - } - setBindData(bound, [func, bitmask, partialArgs, partialRightArgs, thisArg, arity]); - return bound; + var result = (bitmask == 1 || bitmask === 17) + ? baseBind(func, thisArg, partialArgs) + : baseCreateWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity); + + setBindData(result, [func, bitmask, partialArgs, partialRightArgs, thisArg, arity]); + return result; } /** @@ -5354,8 +5379,8 @@ */ function bind(func, thisArg) { return arguments.length > 2 - ? createBound(func, 17, slice(arguments, 2), null, thisArg) - : createBound(func, 1, null, null, thisArg); + ? createWrapper(func, 17, slice(arguments, 2), null, thisArg) + : createWrapper(func, 1, null, null, thisArg); } /** @@ -5389,7 +5414,7 @@ while (++index < length) { var key = funcs[index]; - object[key] = createBound(object[key], 1, null, null, object); + object[key] = createWrapper(object[key], 1, null, null, object); } return object; } @@ -5430,8 +5455,8 @@ */ function bindKey(object, key) { return arguments.length > 2 - ? createBound(key, 19, slice(arguments, 2), null, object) - : createBound(key, 3, null, null, object); + ? createWrapper(key, 19, slice(arguments, 2), null, object) + : createWrapper(key, 3, null, null, object); } /** @@ -5582,7 +5607,7 @@ */ function curry(func, arity) { arity = typeof arity == 'number' ? arity : (+arity || func.length); - return createBound(func, 4, null, null, null, arity); + return createWrapper(func, 4, null, null, null, arity); } /** @@ -5876,7 +5901,7 @@ * // => 'hi fred' */ function partial(func) { - return createBound(func, 16, slice(arguments, 1)); + return createWrapper(func, 16, slice(arguments, 1)); } /** @@ -5907,7 +5932,7 @@ * // => { '_': _, 'jq': $ } */ function partialRight(func) { - return createBound(func, 32, null, slice(arguments, 1)); + return createWrapper(func, 32, null, slice(arguments, 1)); } /** @@ -5983,7 +6008,7 @@ * // => '
Fred, Wilma, & Pebbles
' */ function wrap(value, wrapper) { - return createBound(wrapper, 16, [value]); + return createWrapper(wrapper, 16, [value]); } /*--------------------------------------------------------------------------*/ diff --git a/dist/lodash.compat.min.js b/dist/lodash.compat.min.js index a72b930cc..417fe8f75 100644 --- a/dist/lodash.compat.min.js +++ b/dist/lodash.compat.min.js @@ -5,54 +5,54 @@ */ ;(function(){function n(n,t,e){e=(e||0)-1;for(var r=n?n.length:0;++eFred, Wilma, & Pebbles
' */ function wrap(value, wrapper) { - return createBound(wrapper, 16, [value]); + return createWrapper(wrapper, 16, [value]); } /*--------------------------------------------------------------------------*/ diff --git a/dist/lodash.min.js b/dist/lodash.min.js index e5530de38..b93ef8723 100644 --- a/dist/lodash.min.js +++ b/dist/lodash.min.js @@ -5,50 +5,50 @@ */ ;(function(){function n(n,t,e){e=(e||0)-1;for(var r=n?n.length:0;++eFred, Wilma, & Pebbles
' */ function wrap(value, wrapper) { - return createBound(wrapper, 16, [value]); + return createWrapper(wrapper, 16, [value]); } /*--------------------------------------------------------------------------*/ diff --git a/dist/lodash.underscore.min.js b/dist/lodash.underscore.min.js index 4600a16db..4e4669411 100644 --- a/dist/lodash.underscore.min.js +++ b/dist/lodash.underscore.min.js @@ -3,37 +3,37 @@ * Lo-Dash 2.2.1 (Custom Build) lodash.com/license | Underscore.js 1.5.2 underscorejs.org/LICENSE * Build: `lodash underscore exports="amd,commonjs,global,node" -o ./dist/lodash.underscore.js` */ -;(function(){function n(n,r,t){t=(t||0)-1;for(var e=n?n.length:0;++tFred, Wilma, & Pebbles
' */ function wrap(value, wrapper) { - return createBound(wrapper, 16, [value]); + return createWrapper(wrapper, 16, [value]); } /*--------------------------------------------------------------------------*/