Throttle Frequency
Simple vanilla JavaScript tool to throttle execution frequency of any given function - time in milliseconds, no initial delay, optional scope declaration.
Installation
Install via npm
$ npm install throttle-frequency
... or yarn
$ yarn add throttle-frequency
then require
var throttleFrequency = ;
or import
Usage
throttleFrequency(func, delay, scope);
- param {function} func - function to execute
- param {number} delay - delay in milisecionds
- param {object} scope - optional scope in which function will be executed
- return {function} - wrapped func
Examples
Throttling variable manipulation:
var test;var { test = arg; };var testFuncThrottled = ; ;console; // 'TEST 1!' ; ;console; // 'TEST 1!'
Emitting debounced window resize event - a little bit more practical example
var { var newEvent = document; newEvent; newEventdata = data; window;}; var { var { ; }; var debounced = ; optselement;}; ; window;
Author
Kuba Paczyński
License
Copyright © 2017, Kuba Paczyński. Released under the MIT License.