在Javascript Backbone类中调用Super方法
Calling Super Method in Javascript Backbone Class
我有一个扩展Backbone.View的基类。我希望能够在重写子类上的"initialize"后调用super的"initiate"。如何以最健壮、最清晰的方式调用javascript中扩展类的super?
我已经看到了这一点(骨干中的超级),有没有一种更清晰的方法来实现这一点,而不必事先知道超级班是谁?
App.Views.BaseView = Backbone.View.extend({
initialize: function(templateContext){
this.super_called = true;
}
});
对于我的所有子视图,我希望利用已经编写的initialize函数。
App.Views.ChildViewWorks = App.Views.extend({});
var newView = new App.Views.ChildViewWorks();
alert(newView.super_called); // print true
App.Views.ChildViewDoesNotWork = App.Views.extend({
initialize: function(templateContext){
this.super_called = false;
//what line of code can I add here to call the super initialize()?
}
});
var newViewWrong = new App.Views.ChildViewDoesNotWork();
alert(newViewWrong.super_called); //now equal to false because I have not called the super.
App.Views.ChildViewDoesNotWork = App.Views.BaseView.extend({
initialize: function(templateContext){
this.super_called = false;
App.Views.BaseView.prototype.initialize.call(this);
}
});
相关文章:
- 如何使jQuery插件函数可调用以供独立使用,而不在集合上操作
- D3在一个调用中绘制不同的SVG形状,没有可见性
- 如何从Java/scala调用js美化程序
- 如何调用这个匿名 JavaScript 函数
- 如何从模块链中调用函数.导出到节点中
- 我需要从php调用javascript或jquery
- Chrome开发工具(如何知道我在调用哪个javascript对象)
- 单击按钮后如何逐个调用分区,上一个分区将隐藏
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- 带有super()调用的Javascript继承
- 在Javascript Backbone类中调用Super方法
- 在Babel下调用super()时,由于自定义错误,无法输出堆栈
- 重写Javascript本机方法并调用super
- “super”可以调用基类的方法和属性
- 确定是否从继承类调用super()
- 在React构造函数中调用super()做什么?
- 如何继承Express路由器并在里面调用super方法
- 嘲弄/ stub ' super '调用
- 如何在JavaScript中调用super/base方法