Monday, May 20, 2024
121
rated 0 times [  123] [ 2]  / answers: 1 / hits: 24391  / 13 Years ago, fri, december 2, 2011, 12:00:00

For doing things like



setTimeout(function () {
...
setTimeout(arguments.callee, 100);
}, 100);


I need something like arguments.callee. I found information at javascript.info that arguments.callee is deprecated:




This property is deprecated by ECMA-262 in favor of named function
expressions and for better performance.




But what should be then used instead? Something like this?



setTimeout(function myhandler() {
...
setTimeout(myhandler, 100);
}, 100);
// has a big advantage that myhandler cannot be seen here!!!
// so it doesn't spoil namespace


BTW, is arguments.callee cross-browser compatible?


More From » cross-browser

 Answers
21

Yes, that's what, theoretically, should be used. You're right. However, it doesn't work in some versions of Internet Explorer, as always. So be careful. You may need to fall back on arguments.callee, or, rather, a simple:



function callback() {
// ...
setTimeout(callback, 100);
}

setTimeout(callback, 100);


Which does work on IE.


[#88780] Thursday, December 1, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
chase

Total Points: 78
Total Questions: 106
Total Answers: 93

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
chase questions
Thu, Mar 31, 22, 00:00, 2 Years ago
Thu, Jul 1, 21, 00:00, 3 Years ago
Sat, Dec 12, 20, 00:00, 4 Years ago
Mon, Sep 14, 20, 00:00, 4 Years ago
;