throttle (target, method, args*, spacing, immediate) Array
public
Ensure that the target method is never called more frequently than the specified spacing period. The target method is called immediately.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | function whoRan() { console.log( this .name + ' ran.' ); } let myContext = { name: 'throttle' }; run.throttle(myContext, whoRan, 150); // whoRan is invoked with context myContext // console logs 'throttle ran.' // 50ms passes run.throttle(myContext, whoRan, 150); // 50ms passes run.throttle(myContext, whoRan, 150); // 150ms passes run.throttle(myContext, whoRan, 150); // whoRan is invoked with context myContext // console logs 'throttle ran.' |
Parameters:
-
target
[Object]
- target of method to invoke
-
method
Function|String
- The method to invoke. May be a function or a string. If you pass a string then it will be looked up on the passed target.
-
args*
[Object]
- Optional arguments to pass to the timeout.
-
spacing
Number
- Number of milliseconds to space out requests.
-
immediate
Boolean
- Trigger the function on the leading instead of the trailing edge of the wait interval. Defaults to true.
Returns:
-
Array
- Timer information for use in cancelling, see `run.cancel`.
Please login to continue.