0
請通過代碼JavaScript類澄清
function Item()
{
this.state = 0;
}
Item.prototype.SendRequest = function()
{
//some request callback returns and calls GotResult
var that = this;
{
that.GotResult();//used 'that' because its inside another block
}
}
Item.prototype.GotResult = function()
{
//add to local db with callback which calls AddedToLocalDb
var that = this;
// Here is where the problem is
{
that.AddedToLocalDb();//..... ERROR
}
}
Item.prototype.AddedToLocalDb = function()
{
}
在 「this.AddedToLocalDb()」 我得到它的定義。這是爲什麼?有任何想法嗎? 在該塊上,'this'變量未定義。我犯了一個錯誤還是有一個範圍問題。任何幫助,將不勝感激。
非常感謝。這工作。 :) – ArvindSadasivam
順便說一句我加了gotresult.bind(that); – ArvindSadasivam