JavaScript でオブジェクトを使用するのは初めてです。このチュートリアルのメソッド 1.1 を使用しました。次のコードがあります。
function MyClass() {
this.currentTime = 0;
this.start = function() {
this.currentTime = new Date().getTime();
console.log(this.currentTime); //this line prints the time i just set
this.intervalID = setInterval(this.step, 25);
};
this.step = function() {
var d = new Date().getTime();
console.log(this.currentTime); //always prints "undefined" to the console
};
this.stop = function() {
clearInterval(this.intervalID);
};
}
問題は、step()
関数で設定されているconsole.log(this.currentTime)
間、常に「未定義」と出力されることです。this.currentTime
start()
なんで?私は何が欠けていますか?