0

Whats wrong in below JSON Object definition

I am trying to create a new JSON Object like below. So that my idea is to access COMPANYSETUP.HourSetup.initiate();

Not sure the error ?

COMPANYSETUP = {            
                    initiated : false,          
                     companyId : "",

            initiate : function() {
                if(!initiated){
                    // TO DO
                    initiated = true;
                }           },

            HourSetup = {
                initiated : false,
                    hourId : "",

                    initiate : function() {
                       if(!initiated){
                          // TO DO
                         initiated = true;
                        }
                   }

            }

        };
3
  • I think you confuse JSON with JavaScript objects. Your example is not JSON. I'd looks like you'd like to create some kind of module here. Commented Sep 9, 2009 at 13:55
  • Is this how your code is actually formatted regarding new lines? If so, the comments on lines 3 and 7 are commenting out the rest of the line, which will cause syntax errors. Commented Sep 9, 2009 at 13:55
  • 1
    I've tried to fix the codeblock and weird indentation. If this is how it's supposed to be, there's also a syntax error where HourSetup={} should be HourSetup: {}. Edit: OK, the weird indentation is back ;-) Commented Sep 9, 2009 at 14:00

3 Answers 3

2

Assuming you want a javascript object and not JSON, which disallows functions,

HourSetup =

Should be changed to:

HourSetup :

Also, as JonoW points out, your single line comments are including some of your code as the code is formatted in the post.

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

Comments

1

There's a "=" that shouldn't be there. Change it to ":"

Comments

0

JSON is a form of JavaScript deliberately restricted for safety. It cannot include dangerous code elements like function expressions.

It should work OK in plain eval()ed JavaScript, but it's not JSON.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.