自分自身を再帰的に呼び出すメソッドを持つ 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() の 2 番目の形式を使用して、メソッド自体への参照を渡しました。しかし、それは機能しません。