Here is code, I've been struggling for hours with that, idea is to keep track of how many instances is created, but also make possible to call static method and change/update static member. There is similar question, but I can't implement any solution to my problem.
// object constructor
function Foo() {
this.publicProperty = "This is public property";
}
// static property
Foo.staticProperty = "This is static property";
// static method
Foo.returnFooStaticProperty = function() {
return Foo.staticProperty;
};
console.log("Static member on class: " + Foo.staticProperty); // This is static property
console.log("Result of static method: " + Foo.returnFooStaticProperty()); //This is static property
var myFoo = new Foo();
console.log("myFoo static property is: " + myFoo.staticProperty); // undefined
For sake of simplicity I have changed constructor and member names here. I think it is obvious what happening. I want both of constructor object and instance share same static property.
I can access static member on constructor object, but on instance I got undefined.