1 var apply = require('./_apply'),
2 createCtor = require('./_createCtor'),
3 root = require('./_root');
5 /** Used to compose bitmasks for function metadata. */
9 * Creates a function that wraps `func` to invoke it with the `this` binding
10 * of `thisArg` and `partials` prepended to the arguments it receives.
13 * @param {Function} func The function to wrap.
14 * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
15 * @param {*} thisArg The `this` binding of `func`.
16 * @param {Array} partials The arguments to prepend to those provided to
18 * @returns {Function} Returns the new wrapped function.
20 function createPartial(func, bitmask, thisArg, partials) {
21 var isBind = bitmask & BIND_FLAG,
22 Ctor = createCtor(func);
26 argsLength = arguments.length,
28 leftLength = partials.length,
29 args = Array(leftLength + argsLength),
30 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
32 while (++leftIndex < leftLength) {
33 args[leftIndex] = partials[leftIndex];
35 while (argsLength--) {
36 args[leftIndex++] = arguments[++argsIndex];
38 return apply(fn, isBind ? thisArg : this, args);
43 module.exports = createPartial;