1 | import apply from './_apply.js';
|
2 | import createCtor from './_createCtor.js';
|
3 | import root from './_root.js';
|
4 |
|
5 |
|
6 | var WRAP_BIND_FLAG = 1;
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | function 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 |
|
43 | export default createPartial;
|