[英]Is there a way call the current function (and it's arguments) again after a Timeout in JavaScript?
例:
function foo(){
setTimeout(/*function(){foo(and all arguments);}*/, 2000);
}
有什么辦法可以在超時后再次調用相同的函數。 我遇到的問題是參數不是字符串,而是節點。 例如:
foo(document.body, document.getElementById('header'));
你的問題讓我覺得你正在努力做到這一點
HTML
<div id="header"></div>
使用Javascript
function foo() {
setTimeout((function (that, args) {
return function () {
foo.apply(that, args);
};
}(this, arguments)), 2000);
console.log(arguments);
}
foo(document.body, document.getElementById('header'));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.