A good way to create objects that support public and private properties is to use the factory function:
function createObj(){ var privateVariable = "private"; var result = {}; result.publicProp = 12; result.publicMethod = function() { alert(this.publicProp); alert(privateVariable); };
As for statics, you can simulate them by putting them in the function itself
createObj.staticProperty1 = "sorta static";
And to see the dynamic properties in action:
var obj = createObj(); obj.createProperty("foo", "bar"); alert(obj.foo);
source share