9c7aaa9c27ec777830e5c8b59e3195b676e4b6371e9e23c60342016dd6f044ff650dc796c06e9b2bd4c0c11c9b3778885b3cef48ae0e1307614f5df05c567e 853 B

12345678910111213141516171819202122232425262728
  1. var createCtor = require('./_createCtor'),
  2. root = require('./_root');
  3. /** Used to compose bitmasks for function metadata. */
  4. var WRAP_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 flags. See `createWrap` for more details.
  12. * @param {*} [thisArg] The `this` binding of `func`.
  13. * @returns {Function} Returns the new wrapped function.
  14. */
  15. function createBind(func, bitmask, thisArg) {
  16. var isBind = bitmask & WRAP_BIND_FLAG,
  17. Ctor = createCtor(func);
  18. function wrapper() {
  19. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  20. return fn.apply(isBind ? thisArg : this, arguments);
  21. }
  22. return wrapper;
  23. }
  24. module.exports = createBind;