I need constructor that initialize some Objects with unique name. I write some code like this:
Obj.prototype.idCounter = 0;
Obj = function() {
this.name = "Obj_" + Obj.prototype.idCounter;
Obj.prototype.idCounter++;
}
var o1 = new Obj();
var o2 = new Obj();
alert(o1.name); // Obj_0
alert(o2.name); // Obj_1
But Obj.prototype.idCounter is non-private. I know how to create private variable, but I have no idea how to make private static variable.
Object.getOwnPropertyNames()andObject.getOwnPropertySymbols(). For some purposes, you can use a closure.