2

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',
    complete: 'handleCompletion',
    pass: false,
    debug: false,
    multiRunBlock: false                
}}

I get a syntax error of Uncaught SyntaxError: Unexpected token =

4
  • 4
    Have a look how you assign values to the other properties. Commented Dec 15, 2011 at 15:36
  • use ":" instead of "=" in the code after "defaults" Commented Dec 15, 2011 at 15:36
  • When you're within an object, assign properties using a colon (:) instead of an =. Commented Dec 15, 2011 at 15:36
  • Use jslint or something that uses it, like jsfiddle. Commented Dec 15, 2011 at 15:36

3 Answers 3

8

Use : to separate 'properties' from their respective values:

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

Some reading:

Sign up to request clarification or add additional context in comments.

Comments

2

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',
    complete: 'handleCompletion',
    pass: false,
    debug: false,
    multiRunBlock: false                
  }
};

Comments

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                
}}

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.