2
요소 .popin-foto
에 popin을 엽니 다. 동일한 요소에서 하위 클래스 popin을 열려고하면 작동하지 않습니다.자바 스크립트 상속 : How
이 부모에게있다
코드
function Popin(container, titulo, url_listagem) {
this.url_listagem = url_listagem;
this.titulo = titulo;
this.overlay = $(".popin-overlay");
this.closeButton = $(".popin-close");
this.container = container;
}
Popin.prototype.header = function() {
var dados = {titulo: this.titulo};
var html = $.tmpl("header", dados);
this.container.append(html);
};
Popin.prototype.body = function() {
var html = $.tmpl("body");
this.container.append(html);
};
Popin.prototype.footer = function() {
var html = $.tmpl("footer");
this.container.append(html);
};
Popin.prototype.close = function() {
var self = this;
this.container.hide(100,function(){
self.overlay.fadeOut('fast');
});
$(".popin-header").remove();
$(".popin-body").remove();
$(".popin-footer").remove();
};
Popin.prototype.open = function(){
var self = this;
this.header();
this.body();
this.footer();
this.closeButton.click(function(){
self.close();
});
this.overlay.fadeTo("fast", 0.8, function(){
self.container.show();
});
};
하위 클래스
function PopinFoto(){}
PopinFoto.prototype = new Popin($(".popin-fotos"), "fotos", "fake_url");
PopinFoto.prototype.open = function(){
Popin.prototype.open.call(this);
$(".enviar-foto").die().live('click', function(){
//do something
});
};
그래서, 나는이 수행
var popin = new Popin($(".popin-foto"), "title", "link");
popin.open();
popin.close();
var popinFoto = new PopinFoto($(".popin-foto"), "title", "link");
popinFoto.open(); //this not works
popin.close();
을3210
콘솔에서 오류가 발생하지 않았습니다.
도와 주시겠습니까?
:이 같은
난 당신이 달성하기 위해 노력하고 정확히 모르겠지만, 서브 클래스의 생성자가 직접 슈퍼 클래스의 생성자를 호출 할 필요가 있음을 내기 것 그러나 일하지 않았다. 이 작업을 수행 할 때 Popin의 하위 클래스처럼 PopinFoto가 설정되어 있지 않으므로 parent와 같은 프로토 타입 함수가 없습니다. 예를 들면. –