admin管理员组文章数量:1313001
I'm having a few issues with creating an object within an object, it's syntax related but can't seem to remember how I can achieve this.
ajaxRequest = {
that: null,
request: null,
multiRun: null,
multiRunTimer: null,
defaults={
ext: '',
url: '',
type: "POST",
dataType: "json",
payload: null,
beforeSend: 'handleBefore',
error: 'handleError',
plete: 'handleCompletion',
pass: false,
debug: false,
multiRunBlock: false
}}
I get a syntax error of Uncaught SyntaxError: Unexpected token =
I'm having a few issues with creating an object within an object, it's syntax related but can't seem to remember how I can achieve this.
ajaxRequest = {
that: null,
request: null,
multiRun: null,
multiRunTimer: null,
defaults={
ext: '',
url: '',
type: "POST",
dataType: "json",
payload: null,
beforeSend: 'handleBefore',
error: 'handleError',
plete: 'handleCompletion',
pass: false,
debug: false,
multiRunBlock: false
}}
I get a syntax error of Uncaught SyntaxError: Unexpected token =
Share Improve this question edited Dec 15, 2011 at 15:35 Felix Kling 817k181 gold badges1.1k silver badges1.2k bronze badges asked Dec 15, 2011 at 15:34 DavidDavid 36.5k14 gold badges51 silver badges80 bronze badges 4- 4 Have a look how you assign values to the other properties. – Felix Kling Commented Dec 15, 2011 at 15:36
- use ":" instead of "=" in the code after "defaults" – Kashif Khan Commented Dec 15, 2011 at 15:36
-
When you're within an object, assign properties using a colon (
:
) instead of an=
. – Cᴏʀʏ Commented Dec 15, 2011 at 15:36 - Use jslint or something that uses it, like jsfiddle. – Bakudan Commented Dec 15, 2011 at 15:36
3 Answers
Reset to default 8Use :
to separate 'properties' from their respective values:
defaults: {
ext: '',
url: '',
type: "POST",
dataType: "json",
payload: null,
beforeSend: 'handleBefore',
error: 'handleError',
plete: 'handleCompletion',
pass: false,
debug: false,
multiRunBlock: false
}}
Some reading:
- http://www.dyn-web./tutorials/obj_lit.php
You need a :
instead of =
for defaults.
var ajaxRequest = {
that: null,
request: null,
multiRun: null,
multiRunTimer: null,
defaults: {
ext: '',
url: '',
type: "POST",
dataType: "json",
payload: null,
beforeSend: 'handleBefore',
error: 'handleError',
plete: 'handleCompletion',
pass: false,
debug: false,
multiRunBlock: false
}
};
ajaxRequest = {
that: null,
request: null,
multiRun: null,
multiRunTimer: null,
defaults: {
ext: '',
url: '',
type: "POST",
dataType: "json",
payload: null,
beforeSend: 'handleBefore',
error: 'handleError',
plete: 'handleCompletion',
pass: false,
debug: false,
multiRunBlock: false
}}
As it says, you have an issue with the =
. User =
to assign a variable, but properties within an object should use :
(just like the rest of your properties)
本文标签: jqueryJavascript object within objectStack Overflow
版权声明:本文标题:jquery - Javascript object within object - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741894326a2403489.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论