Skip to content

Instantly share code, notes, and snippets.

@finom finom/procrastinate.js
Last active Mar 31, 2017

Embed
What would you like to do?
procrastinate function
var procrastinate = function ( f, d, thisArg ) {
var timeout;
if( typeof d !== 'number' ) {
thisArg = d;
d = 0;
}
return function() {
var args = arguments,
_this = this;
clearTimeout( timeout );
timeout = setTimeout( function() {
f.apply( thisArg || _this, args );
}, d || 0 );
};
};
/**
var doSomethingHeavy = function( i ) {
console.log( 'Ok', i );
};
var procrastinateSomethingHeavy = MK.procrastinate( doSomethingHeavy );
for( var i = 0; i < 100; i++ ) {
procrastinateSomethingHeavy( i );
}
// >> Ok 100
*/
@obenjiro

This comment has been minimized.

Copy link

obenjiro commented Aug 26, 2014

То что вы "изобрели" называется Debouncing
http://dfilatov.blogspot.ru/2009/05/debouncing.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.