Are you sure you mean static
?
What I mean is, in a more class-dependent language, you might have:
class Person {
static people = 0;
public name;
public age;
public Person (name, age) { this.name = name; this.age = age; Person::people += 1; }
public sayName () { echo this.name; }
static numPeople () { echo Person::people; }
}
Then you might say:
bob = new Person("Bob", 32);
bob.sayName(); // "Bob"
Person::numPeople(); // 1
If you wanted Person::numPeople();
functionality, there's nothing stopping you from adding Object.create.numPeople = function () {};
The question you might want to ask yourself is "Why?"
Are you trying to call static methods like:
bob.constructor.numPeople();
If so, I'm sure that there's a better way around that.
For example, extending the constructor's prototype would provide access to static properties/methods by default.
var personObj = {
sayName : function () { console.log(this.name); },
sayAge : function () { console.log(this.age); }
};
var bob = Object.create(personObj, { name : "Bob", age : 32 });
These are accessed in a way which is similar to traditional inheritance, but static in the sense that each object references the same functions and values, so if that prototype object changes, each constructed instance changes, as well.
Personally, I prefer the freedom of doing most of my object creation inline and on-demand.
If I need to create multiples of the same format, then I'll typically create a factory, rather than creating a constructor or using Object.create.
With a factory, even just a simple one, using one or two levels of closure, you can simulate private properties/methods, and with the second closure, you can simulate "class-wide" private-statics.