做类似的事情
setTimeout(function () {
...
setTimeout(arguments.callee, 100);
}, 100);
我需要像 arguments.callee
这样的东西。我找到了 information at javascript.info arguments.callee
已弃用:
This property is deprecated by ECMA-262 in favor of named function expressions and for better performance.
但是应该用什么来代替?像这样的东西?
setTimeout(function myhandler() {
...
setTimeout(myhandler, 100);
}, 100);
// has a big advantage that myhandler cannot be seen here!!!
// so it doesn't spoil namespace
顺便说一句,arguments.callee
跨浏览器兼容吗?
最佳答案
是的,从理论上讲,这就是应该使用的内容。你是对的。但是,与往常一样,它在某些版本的 Internet Explorer 中不起作用。所以要小心。您可能需要求助于 arguments.callee
,或者更确切地说,一个简单的:
function callback() {
// ...
setTimeout(callback, 100);
}
setTimeout(callback, 100);
哪个在 IE 上有效。
关于javascript - Arguments.callee 已弃用 - 应该改用什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8361642/