Javascript继承:如何
我在元素Javascript继承:如何,javascript,jquery,html,Javascript,Jquery,Html,我在元素中打开一个popin。popin foto。当我尝试在同一元素中打开子类popin时,它不起作用 代码 这是家长 function Popin(container, titulo, url_listagem) { this.url_listagem = url_listagem; this.titulo = titulo; this.overlay = $(".popin-overlay"); this.closeButton = $(".popin-cl
中打开一个popin。popin foto
。当我尝试在同一元素中打开子类popin时,它不起作用
代码
这是家长
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();
在控制台中,未引发任何错误
你能帮我吗?看起来你的子类设置不正确,因为你正在将子类的原型设置为超类的具体实例 我不确定您到底想实现什么,但我敢打赌子类构造函数需要直接调用超类构造函数,类似这样:
function PopinFoto(container, titulo, url_listagem){
Popin.call(this, container, titulo, url_listagem);
}
我试过这个,但没用。当我这样做的时候,它没有设置popinfo像Popin的一个子类,所以它没有父类的原型函数,比如这个.body。