Last active
August 29, 2015 14:00
-
-
Save haribote/11028417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* jquery.reduce.js | |
* - 実行回数を間引くユーティリティ | |
* - jQuery は名前空間を借りているだけ | |
*/ | |
;(function (window, $, undefined) { | |
$.extend({ | |
throttle: function(func, delay) { | |
var context = null; | |
var args = []; | |
var timer = null; | |
var _func = function() { | |
timer = null; | |
func.apply(context, args) | |
context = null; | |
args = []; | |
}; | |
return function () { | |
if (!timer) { | |
context = this; | |
args = arguments; | |
timer = window.setTimeout(_func, delay); | |
} | |
}; | |
}, | |
debounce: function(func, delay) { | |
var context = null; | |
var args = []; | |
var timer = null; | |
var _func = function() { | |
func.apply(context, args); | |
context = null; | |
args = []; | |
}; | |
return function() { | |
context = this; | |
args = arguments; | |
if (timer) { | |
window.clearTimeout(timer); | |
} | |
timer = window.setTimeout(_func, delay); | |
}; | |
} | |
}); | |
})(this, jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment