- Source:
Methods
debounce(ms, func) → {function}
Hold the execution of a function until it has not been called for a specific timeframe.
This is a basic implementation for 90% of all cases, if you need more options and more control over details, have a look at lodash's implementation: https://www.npmjs.com/package/lodash.debounce
Parameters:
Name | Type | Description |
---|---|---|
ms |
Number | timeframe in milliseconds without call before execution |
func |
function | the function to delay the execution of |
- Source:
Throws:
error if ms is no number > 0 or func is not a function
Returns:
the debounced function (parameters will be handed as is to the provided function)
- Type
- function
Example
document.querySelector('input[name=search]').addEventListener('change', debounce(1000, function(){ refreshSearch(); }));