4 ms·
The function: setTimeout(30, function() { myHotDog.getCondiments.apply(myHotDog); }); can actually just be: setTimeout(30, function() { myHotDog.getCon
by kwamenum86 17y ago
The function:
setTimeout(30, function() {
myHotDog.getCondiments.apply(myHotDog);
});
can actually just be:
setTimeout(30, function() {
myHotDog.getCondiments();
});
apply is definitely useful but it just makes the code more verbose in this case.
- nixy 17y agoWhich JS engine allows you to call setTimeout like that? Isn't setTimeout(expression, timeInMs [, args]) the right way to go?
- bouncingsoul 17y agoThat's correct, but the optional args parameter isn't supported in IE. So if you want to use setTimeout or setInterval to call a function with arguments you have to do it as an anonymous function with your function call inside. You're right though that milliseconds should be the second argument, not the first. https://developer.mozilla.org/En/Window.setTimeout https://developer.mozilla.org/En/Window.setTimeout
- kwamenum86 17y agoYes my mistake. milliseconds is the first argument. I just copied the function text verbatim. My real point was that you don't need to use apply in this context,, as the author implied.