2011-12-15 200 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     
}} 

,因为它说,你与=的问题。用户=分配一个变量,但对象内的属性应该使用:(就像其他属性一样)