_executeBound.js 613 B

12345678910111213141516
  1. define(['./_baseCreate', './isObject'], function (_baseCreate, isObject) {
  2. // Internal function to execute `sourceFunc` bound to `context` with optional
  3. // `args`. Determines whether to execute a function as a constructor or as a
  4. // normal function.
  5. function executeBound(sourceFunc, boundFunc, context, callingContext, args) {
  6. if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args);
  7. var self = _baseCreate(sourceFunc.prototype);
  8. var result = sourceFunc.apply(self, args);
  9. if (isObject(result)) return result;
  10. return self;
  11. }
  12. return executeBound;
  13. });