Re: [問題] 關於JS在實做class的手法

看板Ajax作者 (wctang)時間17年前 (2008/09/10 18:42), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/5 (看更多)
※ 引述《ckaha (★閃亮數學推理★)》之銘言: : 由於JS在實做class時 似乎是沒有static的 : 所以不知道各位是怎麼處理這個問題 : 因為當class利用到 : function Snack(name){ : this.name = name; : ..... : } : Snack.prototype.GO = function() { : this.KEY do something ..... : setTimeout(this.name+".GO()",this.velocity); : }; : Snack.prototype.ChangeKey(event){ : change this.KEY .... 沒看你完整的程式,但以這裡的程式來看,這裡就有問題。 這裡的 this 是 document 不是 Gsnack, 因為是由 document 的 onkeypress 所觸發的... : } : Snack.prototype.Setup(){ : document.onkeypress = this.ChangeKey; : } : var Gsnack = new Snack("Gsnack"); : Gsnack.setup(); -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.125.148.101

09/10 21:00, , 1F
謝謝您,您說的沒錯 問題就在這裡~
09/10 21:00, 1F
文章代碼(AID): #18nwIf3D (Ajax)
文章代碼(AID): #18nwIf3D (Ajax)