[code]
js继承
第一种继承
var A = {name:"diaoer",show:function(){
alert(this.name);
}
}
var B = {};
for (var i in A) {
B[i]=A[i];
}
B.show();
第二种继承
function A() {
this.name="diaoers";
this.show=function(){
alert(this.name);
}
}
function B(){
this.b=A;
this.b();
delete this.b;
}
var o = new B();
o.show();
第三种继承
function A(name) {
this.name=name;
this.show=function(){
alert(this.name);
}
}
function B(){
A.call(this,'张三');//它的参数是一个一个传的 而例外一种方式就是通过apply方法来创建 它 后面的参数是一个数组或者argments对象
}
var o = new B();
o.show();
第四种继承
function A(name) {
this.name=name;
this.show=function(){
alert(this.name);
}
}
function B(){
A.apply(this,['张三']);
}
var o = new B();
o.show();
第五种方式
function A(name) {
this.name=name;
this.show=function(){
alert(this.name);
}
}
function B(){
}
B.prototype=new A("diaoer");
var o = new B();
o.show();
[/code]