Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function (global) {
- 'use strict';
- var eventUtils = {
- debounce: function (fn, delay) {
- var timer = null;
- return function () {
- var context = this, args = arguments;
- clearTimeout(timer);
- timer = setTimeout(function () {
- fn.apply(context, args);
- }, delay);
- }
- },
- throttle: function (fn, threshhold, scope) {
- threshhold || (threshhold = 250);
- var last,
- deferTimer;
- return function () {
- var context = scope || this;
- var now = +new Date,
- args = arguments;
- if (last && now < last + threshhold) {
- // hold on to it
- clearTimeout(deferTimer);
- deferTimer = setTimeout(function () {
- last = now;
- fn.apply(context, args);
- }, threshhold);
- } else {
- last = now;
- fn.apply(context, args);
- }
- }
- }
- };
- // AMD support
- if (typeof define === 'function' && define.amd) {
- define(function () { return eventUtils; });
- // CommonJS and Node.js module support.
- } else if (typeof exports !== 'undefined') {
- // Support Node.js specific `module.exports` (which can be a function)
- if (typeof module !== 'undefined' && module.exports) {
- exports = module.exports = eventUtils;
- }
- // But always support CommonJS module 1.1.1 spec (`exports` cannot be a function)
- exports.eventUtils = eventUtils;
- } else {
- global.eventUtils = eventUtils;
- }
- })(this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement