wrapFunction.js 875 B

1234567891011121314151617181920212223242526
  1. import DeveloperError from './DeveloperError.js';
  2. /**
  3. * Wraps a function on the provided objects with another function called in the
  4. * object's context so that the new function is always called immediately
  5. * before the old one.
  6. *
  7. * @private
  8. */
  9. function wrapFunction(obj, oldFunction, newFunction) {
  10. //>>includeStart('debug', pragmas.debug);
  11. if (typeof oldFunction !== 'function') {
  12. throw new DeveloperError('oldFunction is required to be a function.');
  13. }
  14. if (typeof newFunction !== 'function') {
  15. throw new DeveloperError('oldFunction is required to be a function.');
  16. }
  17. //>>includeEnd('debug');
  18. return function() {
  19. newFunction.apply(obj, arguments);
  20. oldFunction.apply(obj, arguments);
  21. };
  22. }
  23. export default wrapFunction;