Given a key and a set of arguments, call them when given a context. Primarily useful in composition.
Use a closure to call a stored key with stored arguments.
constcall=(key,...args)=> context => context[key](...args);
@@ -927,6 +927,33 @@ document.bodyawaitsleep(1000);
console.log('I woke up after 1 second.');
}
+
throttle
Creates a throttled function that only invokes the provided function at most once per every wait milliseconds
Use setTimeout() and clearTimeout() to throttle the given method, fn. Use Function.apply() to apply the this context to the function and provide the necessary arguments. Use Date.now() to keep track of the last time the throttled function was invoked. Omit the second argument, wait, to set the timeout at a default of 0 ms.
window.addEventListener(
+ 'resize',
+ throttle(function(evt) {
+ console.log(window.innerWidth);
+ console.log(window.innerHeight);
+ },250)
+);// Will log the window dimensions at most every 250ms
times
Iterates over a callback n times
Use Function.call() to call fnn times or until it returns false. Omit the last argument, context, to use an undefined object (or the global object in non-strict mode).