Is this the return expression in the _.delay underscore.js function extraneous?
This is the code for _.delay
:
// Delays a function for the given number of milliseconds, and then calls
// it with the arguments supplied.
_.delay = function(func, wait) {
var args = slice.call(arguments, 2);
return setTimeout(function() {
return func.apply(null, args);
}, wait);
};
The first statement return
before is setTimeout
definitely useful because it returns timeoutID
, which you can use to cancel the timer. No questions.
However, I don't see how an operator return
inside a function passed to setTimeout
can have any effect since it setTimeout
is asynchronous. Is this an internal expression by an return
outsider?
To access this asynchronous result, a promise or similar construct must be registered.
underscore.js
- a well polished library that tries to limit the number of bytes; therefore, it seems strange that such an external statement would be present.
source to share
No one has answered this question yet
See similar questions:
or similar: