Invoking Throttled Functions
How to use Lodash to throttle functions and turn off the thrailing edge to avoid strange behaviour.
by Adam Boduch
JavaScript
function obj() {}
obj.prototype.log = _.throttle( function() {
console.info( 'called log()' );
}, 200, { trailing: false } );
_( new Array( 500000 ) )
.map( function() {
return new obj();
})
.tap( function() {
console.time( 'elapsed' );
})
.invoke( 'log' );
console.timeEnd( 'elapsed' );