1 var apply = require('./apply'),
2 createCtorWrapper = require('./createCtorWrapper');
4 /** Used to compose bitmasks for wrapper metadata. */
8 * Creates a function that wraps `func` to invoke it with the optional `this`
9 * binding of `thisArg` and the `partials` prepended to those provided to
13 * @param {Function} func The function to wrap.
14 * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper` for more details.
15 * @param {*} thisArg The `this` binding of `func`.
16 * @param {Array} partials The arguments to prepend to those provided to the new function.
17 * @returns {Function} Returns the new wrapped function.
19 function createPartialWrapper(func, bitmask, thisArg, partials) {
20 var isBind = bitmask & BIND_FLAG,
21 Ctor = createCtorWrapper(func);
25 argsLength = arguments.length,
27 leftLength = partials.length,
28 args = Array(leftLength + argsLength),
29 fn = (this && this !== global && this instanceof wrapper) ? Ctor : func;
31 while (++leftIndex < leftLength) {
32 args[leftIndex] = partials[leftIndex];
34 while (argsLength--) {
35 args[leftIndex++] = arguments[++argsIndex];
37 return apply(fn, isBind ? thisArg : this, args);
42 module.exports = createPartialWrapper;