5

I have seen in EmberJS code and discussion {no references supplied} the following:

Code

route.js

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

Questions

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.

Liam
  • 27,717
  • 28
  • 128
  • 190
datUser
  • 287
  • 7
  • 20

2 Answers2

5

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.

blessanm86
  • 31,439
  • 14
  • 68
  • 79
2

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/

RyanHirsch
  • 1,847
  • 1
  • 22
  • 37