I have seen in EmberJS code and discussion {no references supplied} the following:
route.js
setupController: function (controller, model) {
this._super(controller,model);
// More code
},
What is the call to this._super(controller,model);
doing here?
When should I need to use this type of call?
Just trying to learn here as my nose bleeds from the Ember learning curve.
What is a Controller? A Controller is routable object which receives a single property from the Route – model – which is the return value of the Route's model() method. The model is passed from the Route to the Controller by default using the setupController() function.
Ember is not suitable for smaller project since it can overcomplicate the app. Also, it is hard for new specialists to adopt this framework as the learning curve is steep.
What are the prime tasks that are performed by controllers in Ember. js? Decorating the model which is returned by the route is a very essential task that needs to be performed in Ember.
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 of the controller to the model passed in. This is the default implementation. Due to this, in normal situations we do not need to implement this method.
Now we normally override it when we want to set additional data to the controller. In those cases we want the default behavior and our custom stuff. So we call the _super
method. And do our stuff 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 the default implementation of setupController.
this._super(controller, model);
calls the parent implementation for 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 methods but still access the implementation of your parent class by calling the special _super() method"
http://emberjs.com/guides/object-model/reopening-classes-and-instances/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With