2012-12-13 146 views
0

創建對象,我有以下代碼:錯誤在IE8

var APP= APP || {}; 
    APP.settings = { 
     apiRoot: "http://localhost/appapi", 
     siteRoot: "http://localhost", 
    }; 

此代碼在Chrome和Firefox,但在IE8中拋出一個錯誤,Unable to set value of the property 'settings': object is null or undefined

這不是我的代碼,所以我」米有點損失,爲什麼這不起作用?

+1

我的猜測是它是一個保留關鍵字。嘗試'設置'來驗證 – EricG

+0

是的,看起來像你的權利 - 加上我需要從最後的'設置'刪除最後的','字符。 – CLiown

+0

@EriG:爲什麼'settings'是我們自己命名空間中的保留字?你有什麼資料嗎? – Amberlamps

回答

3

問題是您的對象屬性列表中的尾隨逗號,其中IE < 9不喜歡並引發錯誤。刪除它,它會很好。

var APP = APP || {}; 
APP.settings = { 
    apiRoot: "http://localhost/appapi", 
    siteRoot: "http://localhost" // <-- Comma removed here 
}; 
+0

這是設置未在JavaScript中保留的正確答案。 – andlrc