main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
851 bytes
|
Rev | Line | |
---|
[d565449] | 1 | import createCtor from './_createCtor.js';
|
---|
| 2 | import root from './_root.js';
|
---|
| 3 |
|
---|
| 4 | /** Used to compose bitmasks for function metadata. */
|
---|
| 5 | var WRAP_BIND_FLAG = 1;
|
---|
| 6 |
|
---|
| 7 | /**
|
---|
| 8 | * Creates a function that wraps `func` to invoke it with the optional `this`
|
---|
| 9 | * binding of `thisArg`.
|
---|
| 10 | *
|
---|
| 11 | * @private
|
---|
| 12 | * @param {Function} func The function to wrap.
|
---|
| 13 | * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
|
---|
| 14 | * @param {*} [thisArg] The `this` binding of `func`.
|
---|
| 15 | * @returns {Function} Returns the new wrapped function.
|
---|
| 16 | */
|
---|
| 17 | function createBind(func, bitmask, thisArg) {
|
---|
| 18 | var isBind = bitmask & WRAP_BIND_FLAG,
|
---|
| 19 | Ctor = createCtor(func);
|
---|
| 20 |
|
---|
| 21 | function wrapper() {
|
---|
| 22 | var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
---|
| 23 | return fn.apply(isBind ? thisArg : this, arguments);
|
---|
| 24 | }
|
---|
| 25 | return wrapper;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | export default createBind;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.