【发布时间】:2010-09-26 05:27:40
【问题描述】:
我正在编写一个 JavaSCript 类,它有一个递归调用自身的方法。
Scheduler.prototype.updateTimer = function () {
document.write( this._currentTime );
this._currentTime -= 1000;
// recursively calls itself
this._updateUITimerHandler = window.setTimeout( arguments.callee , 1000 );
}
属性描述:
_currentTime: the currentTime of the timer in miliseconds.
_updateUITimerHandler: stores the reference so can be used later with clearTimeout().
我的问题是我在 setTimeout() 中使用递归。我知道 setTimeout() 将接受一些要执行的字符串,或对函数的引用。由于这个函数是一个对象的方法,我不知道如何从外部调用它。所以我使用了 setTimeout() 的第二种格式,并传入了对方法本身的引用。但它不起作用。
【问题讨论】:
-
这不是递归的,只是连续的
标签: javascript recursion