Closed pogman-code closed 9 years ago
An example is pretty simple. On the previous example, just set a class variable within A's constructor. This variable won't be available on a new B() object if we don't call B. parent.constructor.call(this); within B's constructor.
i.e.:
var A = Stapes.subclass({ constructor: function () { this.a = "I'm a"; A.parent.constructor.call(this); } }); var B = A.subclass({ constructor: function () { this.b = "I'm b"; } }); var o2 = new B(); // _guid === 3
In the end o2.a is undefined
2015-02-14 15:38 GMT+01:00 Anders notifications@github.com:
Could you provide a case where you need to call the parent's constructor like this? As far as I can see, what you're trying to do, is already handled internally by Stapes.
— Reply to this email directly or view it on GitHub https://github.com/hay/stapes/issues/60#issuecomment-74377448.
Yup, I'm with you and agree. Should be added to the docs as well.
@Jesus-21 Could you put together a PR and unit test for this?
Hi, first of all, here is a simple test case:
Due to the mechanism of Stapes, when instantiating a subclass that calls its parent's constructor, it adds unnecessary empty objects to .attributes and .eventHandlers. As far as we understood this issue is due to calls to _.addGuid( this, true ) that are triggered through the dynamically generated constructor of subclasses.
In the example above, we can see that the deeper our subclasses are, the more we leak (and that's understandable).
At first I thought of using
As default constructor of _.Module (the default Stapes superclass) and use the following as realConstructor:
The thing with this solution is that it break "events on subclasses" unit test because Parent class' constructor does not call its superclass (Stapes) constructor. Adding
Fixes this test.
To end this ticket, it would be great if you can check that yourselves because we might not understand all inherent mechanism of Stapes and there might be a better solution to this.
Thanks. (And great piece of work anyway!)