嗨我試圖在jQuery中創建一個對象,並且一切正常,但不知何故,我無法通過一些必要的屬性超出setInterval函數BC當我測試它總是彈出「不確定」。這是我的代碼草案。「setInterval」函數是在構造函數中賦值的轉儲屬性
在此先感謝!
function MyFunction(var1){
this.var = var1;
this.var2 = 2;
this.pause = 3000;
this.slideOn();
}
MyFunction.prototype.slideOn = function(){
alert(this.var); //alerts the value
setInterval(function(){ //doesnt work and it alerts "undefined"
alert(this.var2),1000,function(){}
},this.pause // works again with no hassle
};
alert(_this.var2),1000,function(){}應該做什麼? –