2011-12-15 124 views
2

我在創建一個對象內有一些問題,它的語法相關,但似乎無法記住我如何實現這一點。對象內的Javascript對象

ajaxRequest = { 
that: null, 
request: null, 
multiRun: null, 
multiRunTimer: null, 
defaults={ 
    ext: '', 
    url: '', 
    type: "POST", 
    dataType: "json", 
    payload: null, 
    beforeSend: 'handleBefore', 
    error: 'handleError', 
    complete: 'handleCompletion', 
    pass: false, 
    debug: false, 
    multiRunBlock: false     
}} 

我得到未捕獲的SyntaxError的語法錯誤:意外的記號=

+4

查看如何爲其他屬性分配值。 – 2011-12-15 15:36:07

回答

8

使用:分別從各自的價值觀分開 '屬性':

defaults: { 
    ext: '', 
    url: '', 
    type: "POST", 
    dataType: "json", 
    payload: null, 
    beforeSend: 'handleBefore', 
    error: 'handleError', 
    complete: 'handleCompletion', 
    pass: false, 
    debug: false, 
    multiRunBlock: false     
}} 

一些閱讀:

2

您需要一個:而不是=默認值。

var ajaxRequest = { 
that: null, 
request: null, 
multiRun: null, 
multiRunTimer: null, 
defaults: { 
    ext: '', 
    url: '', 
    type: "POST", 
    dataType: "json", 
    payload: null, 
    beforeSend: 'handleBefore', 
    error: 'handleError', 
    complete: 'handleCompletion', 
    pass: false, 
    debug: false, 
    multiRunBlock: false     
    } 
}; 
2
ajaxRequest = { 
that: null, 
request: null, 
multiRun: null, 
multiRunTimer: null, 
defaults: { 
    ext: '', 
    url: '', 
    type: "POST", 
    dataType: "json", 
    payload: null, 
    beforeSend: 'handleBefore', 
    error: 'handleError', 
    complete: 'handleCompletion', 
    pass: false, 
    debug: false, 
    multiRunBlock: false     
}} 

,因爲它說,你與=的問題。用戶=分配一個變量,但對象內的屬性應該使用:(就像其他屬性一樣)