SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist anjanesh's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai
    Posts
    447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Object static members

    Hi

    Code JavaScript:
    function foo1()
     {
            this.m = 0;
     }
     
    foo1.prototype.c1 = 5;
     
    alert(foo1.c1);
    returns undefined.

    Isnt there a way to create a class constant/static members ?

    Thanks
    Anjanesh

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    foo1.c1 = 5;

  3. #3
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, if you want to use your prototype you can create an instance for that object e.g
    Code JavaScript:
    function foo1()
     {
            this.m = 0;
     }
     
    foo1.prototype.c1 = 5;
     
    var f=new foo1(); 
    alert(f.c1);
    alert(f.m);


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •