<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
//a类
function a(att){
this.att=att;
}
a.prototype.show=function(){
alert(this.att);
};
//b类继承a
function b(att){
this.att=att;
}
b.prototype.show2=function(){
alert(this.att);
};
b.prototype=new a();
b.prototype.constructor=b;
//c类继承b
function c(att){
this.att=att;
}
c.prototype.show3=function(){
alert(this.att);
};
c.prototype=new b();
c.prototype.constructor=c;var test=new c("test");
test.show();//为什么说找不到方法呢!
</script>
</head>
<body>
</body>
</html>
没问题呀!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
//a类
function a(att){
this.att=att;
}
a.prototype.show=function(){
alert(this.att);
};
//b类继承a
function b(att){
this.att=att;
}
b.prototype.show2=function(){
alert(this.att);
};
b.prototype=new a();
b.prototype.constructor=b;
//c类继承b
function c(att){
this.att=att;
}
c.prototype.show3=function(){
alert(this.att);
};
c.prototype=new b();
c.prototype.constructor=c;var test=new c("test");
test.show();//为什么说找不到方法呢!
</script>
</head>
<body>
</body>
</html>
没问题呀!
是test.show2()和test.show3()找不到吧!要先设置继承,再设置对象的方法//a类
function a(att){
this.att=att;
}
a.prototype.show=function(){
alert(this.att);
};
//b类继承a
function b(att){
this.att=att;
}
b.prototype=new a();
b.prototype.constructor=b;
b.prototype.show2=function(){
alert(this.att);
};
//c类继承b
function c(att){
this.att=att;
}
c.prototype=new b();
c.prototype.constructor=c;
c.prototype.show3=function(){
alert(this.att);
};var test=new c("test");
test.show();
test.show2();
test.show3();