Skip to content

Instantly share code, notes, and snippets.

var mem = function (fn) {
var called = 0;
return function () {
var args = Array.prototype.slice.call(arguments);
called += 1;
return {
returned: fn.apply(null, args),
called: called
@DerekCuevas
DerekCuevas / delay.js
Last active August 29, 2015 14:25
Returns a function that has a timeout of 'delay' seconds, the timeout resets every time the function is called, useful for delaying keyboard events when a user is typing.
/**
* Returns a function that has a timeout of 'delay' seconds,
* the timeout resets every time the function is called. However if
* the (optional) except function returns true, the function will not be called.
*
* Useful for delaying and blocking keyboard events when a user is typing.
*
* @param {Number} delay timeout in milliseconds
* @param {Function} fn the base function
* @param {Function} except