Static properties of Class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #1

    Static properties of Class

    Actually a function is treated as a Class in JavaScript.

    Code:
    function MyClass(){
    
    }
    
    MyClass.prop = 100;
    var mc = new MyClass();
    Why mc.prop returns undefined?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    because prop is a member of the MyClass Function object not the MyClass object. when you call the constructor, it executes the function specifyed (MyClass()), this functions returns an empty object.

    Comment

    Working...