Niger
Niger

Reputation: 4006

Defining recrussive JSON Object notation

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

            }

        };

Upvotes: 0

Views: 332

Answers (3)

w35l3y
w35l3y

Reputation: 8783

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

Upvotes: 1

Jonas Høgh
Jonas Høgh

Reputation: 10874

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.

Upvotes: 2

bobince
bobince

Reputation: 536615

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.

Upvotes: 0

Related Questions