Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. (function (global) {
  2. 'use strict';
  3.  
  4. var eventUtils = {
  5. debounce: function (fn, delay) {
  6. var timer = null;
  7. return function () {
  8. var context = this, args = arguments;
  9. clearTimeout(timer);
  10. timer = setTimeout(function () {
  11. fn.apply(context, args);
  12. }, delay);
  13. }
  14. },
  15. throttle: function (fn, threshhold, scope) {
  16. threshhold || (threshhold = 250);
  17. var last,
  18. deferTimer;
  19. return function () {
  20. var context = scope || this;
  21.  
  22. var now = +new Date,
  23. args = arguments;
  24. if (last && now < last + threshhold) {
  25. // hold on to it
  26. clearTimeout(deferTimer);
  27. deferTimer = setTimeout(function () {
  28. last = now;
  29. fn.apply(context, args);
  30. }, threshhold);
  31. } else {
  32. last = now;
  33. fn.apply(context, args);
  34. }
  35. }
  36. }
  37. };
  38.  
  39. // AMD support
  40. if (typeof define === 'function' && define.amd) {
  41. define(function () { return eventUtils; });
  42. // CommonJS and Node.js module support.
  43. } else if (typeof exports !== 'undefined') {
  44. // Support Node.js specific `module.exports` (which can be a function)
  45. if (typeof module !== 'undefined' && module.exports) {
  46. exports = module.exports = eventUtils;
  47. }
  48. // But always support CommonJS module 1.1.1 spec (`exports` cannot be a function)
  49. exports.eventUtils = eventUtils;
  50. } else {
  51. global.eventUtils = eventUtils;
  52. }
  53. })(this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement