當我調用方法getResult
時,它返回一個未定義的值。我究竟做錯了什麼?JavaScript - 使用對象和方法?
var MyObjectResult = {"Success":1, "Fail":2, "Timeout":3, "None":4}
function MyObject()
{
this.result = MyObjectResult.None;
this.timout = 15;
this.getResult = function()
{
// Some calculation here and changing result
// Logging (this.result shows that result has value of 1)
this.result = MyObjectResult.Success;
return this.result;
}
}
var myObject = new MyObject();
var result = myObject.getResult();
// result is undefined
我沒有看到上面的代碼錯誤。問題可能在於缺少計算代碼嗎?如果你按原樣運行它,它會對你有用嗎? – nnnnnn