jeudi 20 mars 2014

extending controllers - expected behaviour?

Found an issue when extending controllers -

So I have ControllerA and in its init function I add a few listeners.



I then create ControllerB which extends ControllerA.

Now when I load the application it creates all of my controllers and runs through there init() functions as expected.



But as ControllerA was extended by ControllerB, ControllerA's init() function is called twice and adds the same event listeners twice - which in turn means that the function handlers for the events get called twice.

Is this expected behaviour? Should you just not extend a controller that you've created and instead use composition instead of inheritance?

So ControllerB would have a reference to ControllerA rather than extending it?




Aucun commentaire:

Enregistrer un commentaire