source: imaps-frontend/node_modules/lodash-es/_createPartial.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import apply from './_apply.js';
2import createCtor from './_createCtor.js';
3import root from './_root.js';
4
5/** Used to compose bitmasks for function metadata. */
6var WRAP_BIND_FLAG = 1;
7
8/**
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.
11 *
12 * @private
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
17 * the new function.
18 * @returns {Function} Returns the new wrapped function.
19 */
20function createPartial(func, bitmask, thisArg, partials) {
21 var isBind = bitmask & WRAP_BIND_FLAG,
22 Ctor = createCtor(func);
23
24 function wrapper() {
25 var argsIndex = -1,
26 argsLength = arguments.length,
27 leftIndex = -1,
28 leftLength = partials.length,
29 args = Array(leftLength + argsLength),
30 fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
31
32 while (++leftIndex < leftLength) {
33 args[leftIndex] = partials[leftIndex];
34 }
35 while (argsLength--) {
36 args[leftIndex++] = arguments[++argsIndex];
37 }
38 return apply(fn, isBind ? thisArg : this, args);
39 }
40 return wrapper;
41}
42
43export default createPartial;
Note: See TracBrowser for help on using the repository browser.