1 var createCtorWrapper = require('./createCtorWrapper');
3 /** Used to compose bitmasks for wrapper metadata. */
7 * Creates a function that wraps `func` and invokes it with the optional `this`
8 * binding of `thisArg` and the `partials` prepended to those provided to
12 * @param {Function} func The function to partially apply arguments to.
13 * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
14 * @param {*} thisArg The `this` binding of `func`.
15 * @param {Array} partials The arguments to prepend to those provided to the new function.
16 * @returns {Function} Returns the new bound function.
18 function createPartialWrapper(func, bitmask, thisArg, partials) {
19 var isBind = bitmask & BIND_FLAG,
20 Ctor = createCtorWrapper(func);
23 // Avoid `arguments` object use disqualifying optimizations by
24 // converting it to an array before providing it `func`.
26 argsLength = arguments.length,
28 leftLength = partials.length,
29 args = Array(leftLength + argsLength);
31 while (++leftIndex < leftLength) {
32 args[leftIndex] = partials[leftIndex];
34 while (argsLength--) {
35 args[leftIndex++] = arguments[++argsIndex];
37 var fn = (this && this !== global && this instanceof wrapper) ? Ctor : func;
38 return fn.apply(isBind ? thisArg : this, args);
43 module.exports = createPartialWrapper;