throttle should check for valid args (#113)

This commit is contained in:
Lynn
2017-05-27 08:14:39 -07:00
committed by GitHub
parent 2b6139f35a
commit 013b02e04f
2 changed files with 35 additions and 0 deletions

View File

@@ -6,6 +6,12 @@
* @param {function} func function to invoke
*/
function throttle(throttleTime, func) {
if (typeof throttleTime !== 'number' || throttleTime <= 0) {
throw Error('throttle: invalid throttleTime arg, must be a number: ' + throttleTime);
}
if (typeof func !== 'function') {
throw Error('throttle: invalid func arg, must be a function: ' + func);
}
let timer, lastInvoke = 0;
return function() {
let args = arguments;