現(xiàn)在我的代碼按預(yù)期工作,但我不明白this這個(gè)地方的關(guān)鍵字。當(dāng)我嘗試調(diào)用mainLooprequestAnimationFrame 中的方法時(shí),window.requestAnimationFrame(this.mainLoop);它不起作用。當(dāng)我像在我的例子中那樣嘗試它時(shí),它起作用了,但我不明白為什么我不能用 調(diào)用 mainLoop 方法this,同時(shí)能夠用this.methodName();.class Game{ constructor(objects){ //some stuff } temp(){ a.mainLoop(); } mainLoop(){ // some other Methods are being called here window.requestAnimationFrame(this.temp); }}var a = new Game(input); 我希望我能夠解釋?zhuān)业膯?wèn)題。
Javascript:使用此調(diào)用類(lèi)中的方法
泛舟湖上清波郎朗
2021-11-18 17:19:45