tags:

views:

39

answers:

3

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

      }

     };
A: 

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.

bobince
+2  A: 

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.

Jonas H
+1  A: 

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

w35l3y