What does `this._super (controller, model)` mean in Ember Router?

I saw in the EmberJS code and discussion {without links} the following:

the code

route.js

setupController: function (controller, model) { this._super(controller,model); // More code }, 

Questions

What causes the call to this._super(controller,model); here?

When do I need to use this type of call?

Just trying to find out here when my nose is bleeding with the Ember learning curve.

+5
source share
2 answers

As @RyanHirsch said, this._super calls the parent implementation of the method.

In the case of setupController calling this._super(controller,model) will set the model property for the controller to the passed model. This is the default implementation. In this regard, in normal situations, we do not need to implement this method.

Now we usually redefine it when we want to install additional data in the controller. In those cases, we want the default behavior and our custom material. Therefore, we call the _super method. And do our things after that.

 setupController: function (controller, model) { // Call _super for default behavior this._super(controller, model); // Implement your custom setup after controller.set('showingPhotos', true); } 

Here is a standard implementation of setupController.

+5
source

this._super(controller, model); calls the parent implementation of the method (i.e. the object you are extending, so Ember.Route)

http://emberjs.com/guides/object-model/classes-and-instances/

"When defining a subclass, you can override the methods, but still access the implementation of the parent class by calling the special _super () method"

http://emberjs.com/guides/object-model/reopening-classes-and-instances/

+1
source

Source: https://habr.com/ru/post/1211426/


All Articles