The goal - create function, that behaves like class with static methods and at the same time can be used to create instanses. All this resides in dedicated namespace. I am looking for "standard" ptototype approach. And is it good practice in general? I tried to avoid use reference to "class" by function name. If I would have 10 or more static methods it could be difficult. In first example I used _self, and in another method defineProperties.
var MyNamespace = (function() {
function MyClass0(e) {
this.e = e;
var _self = MyClass0;
_self.prototype = {
instanceMethod: function() {
}
}
_self.staticMethod = function() {
}
if (!e) {
return _self;
}
}
function MyClass1(e) {
this.e = e;
MyClass1.prototype = {
instanceMethod: function() {
}
}
var properties = {
staticMethod: {
value: function() {
}
}
};
Object.defineProperties(MyClass1, properties)
if (!e) {
return MyClass1;
}
}
return {
MyClass0: MyClass0(), // use _self
MyClass1: MyClass1() // use defineProperties
}
})();