Last active
May 6, 2018 01:34
-
-
Save vitalii-komenda/50fc05b09ccecaf0e290 to your computer and use it in GitHub Desktop.
Throttle helps to save performance, because it reduces number of calls
This file contains hidden or 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
| // It can be used to save input values after change | |
| // $('input').on('change', throttle(function(){ | |
| // $.ajax(url); | |
| //}, 1000)) | |
| function throttle(fn, time) { | |
| return function inner() { | |
| var args = Array.prototype.slice.call(arguments); | |
| clearTimeout(inner.timeout); | |
| inner.timeout = setTimeout(function () { | |
| fn.apply(null, args); | |
| }, time); | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment