_createBaseWrapper.js 895 B

1234567891011121314151617181920212223242526272829
  1. var createCtorWrapper = require('./_createCtorWrapper'),
  2. root = require('./_root');
  3. /** Used to compose bitmasks for wrapper metadata. */
  4. var BIND_FLAG = 1;
  5. /**
  6. * Creates a function that wraps `func` to invoke it with the optional `this`
  7. * binding of `thisArg`.
  8. *
  9. * @private
  10. * @param {Function} func The function to wrap.
  11. * @param {number} bitmask The bitmask of wrapper flags. See `createWrapper`
  12. * for more details.
  13. * @param {*} [thisArg] The `this` binding of `func`.
  14. * @returns {Function} Returns the new wrapped function.
  15. */
  16. function createBaseWrapper(func, bitmask, thisArg) {
  17. var isBind = bitmask & BIND_FLAG,
  18. Ctor = createCtorWrapper(func);
  19. function wrapper() {
  20. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  21. return fn.apply(isBind ? thisArg : this, arguments);
  22. }
  23. return wrapper;
  24. }
  25. module.exports = createBaseWrapper;