00001 var debounce = require('./debounce'), 00002 isObject = require('./isObject'); 00003 00005 var FUNC_ERROR_TEXT = 'Expected a function'; 00006 00051 function throttle(func, wait, options) { 00052 var leading = true, 00053 trailing = true; 00054 00055 if (typeof func != 'function') { 00056 throw new TypeError(FUNC_ERROR_TEXT); 00057 } 00058 if (isObject(options)) { 00059 leading = 'leading' in options ? !!options.leading : leading; 00060 trailing = 'trailing' in options ? !!options.trailing : trailing; 00061 } 00062 return debounce(func, wait, { 00063 'leading': leading, 00064 'maxWait': wait, 00065 'trailing': trailing 00066 }); 00067 } 00068 00069 module.exports = throttle;