我在对象中创建对象有一些问题,它的语法相关,但似乎无法记住我是如何实现这一点的。
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
}}
我收到Uncaught SyntaxError的语法错误:Unexpected token =
答案 0 :(得分:8)
使用:
将“属性”与其各自的值分开:
defaults: {
ext: '',
url: '',
type: "POST",
dataType: "json",
payload: null,
beforeSend: 'handleBefore',
error: 'handleError',
complete: 'handleCompletion',
pass: false,
debug: false,
multiRunBlock: false
}}
一些阅读:
答案 1 :(得分: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 :(得分: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
}}
正如它所说,=
存在问题。用户=
分配变量,但对象中的属性应使用:
(就像其他属性一样)