1 var composeArgs = require('./_composeArgs'),
2 composeArgsRight = require('./_composeArgsRight'),
3 createCtorWrapper = require('./_createCtorWrapper'),
4 createRecurryWrapper = require('./_createRecurryWrapper'),
5 reorder = require('./_reorder'),
6 replaceHolders = require('./_replaceHolders'),
7 root = require('./_root');
9 /** Used to compose bitmasks for wrapper metadata. */
13 CURRY_RIGHT_FLAG = 16,
18 * Creates a function that wraps `func` to invoke it with optional `this`
19 * binding of `thisArg`, partial application, and currying.
22 * @param {Function|string} func The function or method name to wrap.
23 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
24 * @param {*} [thisArg] The `this` binding of `func`.
25 * @param {Array} [partials] The arguments to prepend to those provided to the new function.
26 * @param {Array} [holders] The `partials` placeholder indexes.
27 * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
28 * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
29 * @param {Array} [argPos] The argument positions of the new function.
30 * @param {number} [ary] The arity cap of `func`.
31 * @param {number} [arity] The arity of `func`.
32 * @returns {Function} Returns the new wrapped function.
34 function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
35 var isAry = bitmask & ARY_FLAG,
36 isBind = bitmask & BIND_FLAG,
37 isBindKey = bitmask & BIND_KEY_FLAG,
38 isCurry = bitmask & CURRY_FLAG,
39 isCurryRight = bitmask & CURRY_RIGHT_FLAG,
40 isFlip = bitmask & FLIP_FLAG,
41 Ctor = isBindKey ? undefined : createCtorWrapper(func);
44 var length = arguments.length,
49 args[index] = arguments[index];
52 args = composeArgs(args, partials, holders);
55 args = composeArgsRight(args, partialsRight, holdersRight);
57 if (isCurry || isCurryRight) {
58 var placeholder = wrapper.placeholder,
59 argsHolders = replaceHolders(args, placeholder);
61 length -= argsHolders.length;
63 return createRecurryWrapper(func, bitmask, createHybridWrapper, placeholder, thisArg, args, argsHolders, argPos, ary, arity - length);
66 var thisBinding = isBind ? thisArg : this,
67 fn = isBindKey ? thisBinding[func] : func;
70 args = reorder(args, argPos);
71 } else if (isFlip && args.length > 1) {
74 if (isAry && ary < args.length) {
77 if (this && this !== root && this instanceof wrapper) {
78 fn = Ctor || createCtorWrapper(fn);
80 return fn.apply(thisBinding, args);
85 module.exports = createHybridWrapper;