版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://syre.blogbus.com/logs/1882084.html
function Base(){
this.foo=function(){
return 'base';
}
}
那怎么实现类的继承呢?
function Derive1(){
this.foo=function(){
return 'derive';
}
}
Derive1.prototype=new Base();
var obj1=new Derive1();
alert(obj1.foo());
还有另外一种方法:
function Derive2(){
this.parent=Base;
this.parent();
this.bar=function(){
return 'bar';
}
}
var obj2=new Derive2;
alert(obj2.foo());
用这种方法还能实现多继承。
function Base2(){
this.bar=function(){
return 'base2';
}
}
function Derive3(){
this.base1=Base;
this.base1();
this.base2=Base2;
this.Base2();
}
var obj3=new Derive3;
alert(obj3.foo());
alert(obj3.bar());
随机文章:
用flash上传文件 2007-10-20
让图片跳舞的js代码 2006-12-31
javascript你可能不知道的5 2006-01-17
javascript你可能不知道的3 2006-01-10
javascript你可能不知道的2 2006-01-06