`this._super(controller,model)` 在 Ember 路由器中意味着什么?
What does the `this._super(controller,model)` mean in an Ember Router?
我在 EmberJS 代码和讨论{未提供参考}中看到以下内容:
代码
route.js
setupController: function (controller, model) {
this._super(controller,model);
// More code
},
问题
这里对 this._super(controller,model);
的调用是做什么的?
我什么时候需要使用这种类型的电话?
只是想在这里学习,因为我的鼻子因 Ember 学习曲线而流血。
this._super(controller, model);
调用方法的父实现(即您要扩展的对象,所以 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 所说,this._super 调用该方法的父实现。
在setupController
的情况下,调用this._super(controller,model)
会将控制器的'model'属性设置为传入的模型。这是默认实现。因此,一般情况下我们不需要实现这个方法。
现在我们通常会在想要为控制器设置额外数据时覆盖它。在那些情况下,我们需要默认行为和自定义内容。所以我们调用 _super
方法。然后做我们的事情。
setupController: function (controller, model) {
// Call _super for default behavior
this._super(controller, model);
// Implement your custom setup after
controller.set('showingPhotos', true);
}
我在 EmberJS 代码和讨论{未提供参考}中看到以下内容:
代码
route.js
setupController: function (controller, model) {
this._super(controller,model);
// More code
},
问题
这里对 this._super(controller,model);
的调用是做什么的?
我什么时候需要使用这种类型的电话?
只是想在这里学习,因为我的鼻子因 Ember 学习曲线而流血。
this._super(controller, model);
调用方法的父实现(即您要扩展的对象,所以 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 所说,this._super 调用该方法的父实现。
在setupController
的情况下,调用this._super(controller,model)
会将控制器的'model'属性设置为传入的模型。这是默认实现。因此,一般情况下我们不需要实现这个方法。
现在我们通常会在想要为控制器设置额外数据时覆盖它。在那些情况下,我们需要默认行为和自定义内容。所以我们调用 _super
方法。然后做我们的事情。
setupController: function (controller, model) {
// Call _super for default behavior
this._super(controller, model);
// Implement your custom setup after
controller.set('showingPhotos', true);
}