The design pattern I use in my current project is:
var MyConstructor = function() { ... };
MyConstructor.STATIC_PROPERTY = 'static';
Now if i want to inherit from MyConstructor class, I'd do:
var ChildClass = function() { ... };
ChildClass.prototype = new MyConstructor(); // Or Object.create(...)
ChildClass.prototype.constructor = ChildClass;
Problem is ChildClass.STATIC_PROPERTY is undefined / not inherited ...
Is there a way to fix that?
Secondary question:
If I console.log(MyConstructor), I'd get function() { ...} and nothing about MyConstructor.STATIC_PROPERTY when it's actually there. Where is that STATIC_PROPERTY stored in the end? How can I check/display it?
console.dir(MyConstructor)to see the static properties.MyConstructor()in the scope where you defineChildClass, something likeChildClass.STATIC_PROPERTY = MyConstructor.STATIC_PROPERTYshould work. ( but might not be desirable ) As stated, it has nothing to do with prototypal inheritance. Nether is it static without usingObject.defineProperty()or it's alternatives. We can overwrite it all we want.