I came across this behavior after using JS for several months. I am very puzzled because of my Java background: create a class and create subclasses. A call to the constructor of the subclass will not call the parent constructor. Ok, I read about this behavior, it seems normal, right?
See this jsfiddle example to help me clarify.
So, so that my subclass constructor runs each of its parent constructor, I add the following (see jsfiddle example
Well, it seems to work better. Now I wonder about the following: Is there a way to indicate if a superclass without a trigger is its constructor? For example, the following method executes Node ():
GameObject.prototype = new Node(); GameObject.prototype.constructor=GameObject;
(see updated jsfiddle example )
I cannot help but feel that I am not doing it right. Since my real model is superimposed on 7 subclasses, it has 21 calls for my constructors (6 + 5 + 4 + 3 + 2 + 1 = 21).
Am I doing something wrong? Thank you for your time!
source share