Your Shape.getName()
function is not initialized until after Shape()
has been called the first time (the initialization code is inside of Shape()
) so thus the Shape.getName
properties does not exist until Shape()
is called.
Perhaps what you want is this:
// define constructor that should only be called with the new operator
function Shape() {
this.namev="naven";
}
// define static methods and properties
// that can be used without an instance
Shape.PIe="3.14";
Shape.getName=function(){
return "nveen test shhsd"
}
// test static methods and properties
alert(Shape.PIe)
alert(Shape.getName())
Remember that in Javascript a function is an object that can have it's own properties just like a plain object. So, in this case you're just using the Shape
function as an object that you can put static properties or methods on. But, do not expect to use this
inside of static methods because they are not connected to any instance. They are static.
If you want instance properties or methods that can uniquely access a Shape object instance, then you would need to create your methods and properties differently (since instance methods or properties are not static).