4 ms·
I do the following a lot (setTimeout as a relevant example): setTimeout( (function(scope){ return function(){scope.fire();}; })(this), 500 );
by sisk 16y ago
I do the following a lot (setTimeout as a relevant example):
setTimeout(
(function(scope){
return function(){scope.fire();};
})(this), 500
);
The short explanation is you return a function from an immediately-executing anonymous function that takes the current scope as a parameter.
- thomasdavis 16y agoI have used this method many times before also, added it as an alternative implementation on the site.