Backbone.View를 확장하는 기본 클래스가 있습니다. 하위 클래스에서 '초기화'를 재정의 한 후 super의 '초기화'를 호출 할 수 있기를 원합니다. 가장 강력하고 명확한 방법으로 자바 스크립트에서 확장 클래스의 수퍼를 호출 할 수 있습니까?Javascript 백본 클래스의 슈퍼 메서드 호출
이 (Super in Backbone)을 보았습니다. 수퍼 클래스가 누구인지 알 필요없이이를 수행하는 명확한 방법이 있습니까?
App.Views.BaseView = Backbone.View.extend({
initialize: function(templateContext){
this.super_called = true;
}
});
모든 하위보기에 대해 이미 작성된 초기화 기능을 활용하고 싶습니다.
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가 정의 된 방법을 제공 할 수 있습니까? – jcbelanger