missing : after property id

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ciary
    Recognized Expert New Member
    • Apr 2009
    • 247

    missing : after property id

    hi all,

    i have a problem with some javascript i've created. im trying to create a new class but on the second line (after i created the class) firebug throws me a 'fatal error: missing : after property id' (wth, how unclear can you be???). i've searched google te find out whats causing it but all things i found were irrelevant to my problem.

    here is the code where the error occurs.
    Code:
    myclass = Class.create({
    				private demo1	        = "";             //ERROR
    				private demo2	        = "";
    				private demo3	        = "";
    
              ...
    
             })
    i've also tried to do it with 'var' instead of 'private' and i also tried 'var myclass = {' but it didnt work either.

    i hope someone can help me out.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    do you use any framework? Class.create() is not a native javascript method. in any case when you write:

    [CODE=javascript]// this are object literals to create a new javascript object
    {}[/CODE]
    you have to use it the following way:

    [CODE=javascript]
    {
    foo: 'bar',
    bar: 'foo'
    }[/CODE]
    kind regards

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      Are you sure that's JavaScript (that script language used on websites) or do you mean Java?

      [edit] darn again, second time today...

      Comment

      • Ciary
        Recognized Expert New Member
        • Apr 2009
        • 247

        #4
        i got it from another javascript library so i'm pretty sure it's javascript. anyhow, when i tried this code it gave nearly the same error, but then on the first line. although this time it was because of a ; rather then a :

        the error: 'fatal error: missing ; before statement'
        Code:
        myclass{                                                            //ERROR
                         private demo1            = "",
                         private demo2            = "",
                         private demo3            = "",
          
                   ...
          
                  }

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          as i already showed you ... the curly brackets are syntactically object literals. when you create a 'class' you would need to write a constructor and its methods unless you use a javascript-lib to 'help' you:

          example for a selfmade 'class'

          [CODE=javascript]function OBJ() {
          this.foo = 'bar';
          this.bar = 'foo';
          }

          var o = new OBJ;

          alert(o.foo);
          [/CODE]
          or when you use a lib it might look like:

          [CODE=javascript]var o = Class.create({
          foo: 'bar',
          bar: 'foo'
          });[/CODE]

          Comment

          • Ciary
            Recognized Expert New Member
            • Apr 2009
            • 247

            #6
            gits, you're the best!!

            its working now. i didn't actually knew what you ment by your first post. that's why i asked again. i'm sorry for that.

            Comment

            • gits
              Recognized Expert Moderator Expert
              • May 2007
              • 5390

              #7
              no problem ... :) ... in case you have more questions just post back to the forum ...

              kind regards

              Comment

              • RamananKalirajan
                Contributor
                • Mar 2008
                • 608

                #8
                class.Create({. ....}); it is used in prototype framework.....

                Comment

                Working...