Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function throttle(fn, delay, context) {
- var timer;
- var context = context || this;
- var first = true;
- return function() {
- if (first) {
- fn.apply(context, [].slice.apply(arguments));
- first = false;
- }
- if (timer) {
- return;
- }
- timer = setTimeout(function() {
- clearTimeout(timer);
- timer = null;
- fn.apply(context, [].slice.apply(arguments));
- }, delay);
- }
- }
- function debounce(fn, delay, context) {
- var timer;
- var context = context ||this;
- return function() {
- clearTimeout(timer);
- timer = setTimeout(fn || function() {
- fn.apply(context, [].slice(arguments));
- }, delay);
- }
- }
Add Comment
Please, Sign In to add comment