<html>
<head>
<script type="text/javascript">
//构造函数构造js类
function user1(){
this.name="fan";
this.age=23;
this.speak=function (){
alert(""+this.name+":"+this.age);
};
}
//原型构造js类
function user2(){}
user2.prototype.age=11;
user2.prototype.name="zhang";
user2.prototype.speak=function (){
alert(this.name+":"+this.age);
}
//原型、构造共同构造js类
function user3(){
this.name="kuang";
this.age=21;
}
user3.prototype.speak=function (){alert(this.name+":"+this.age);}
//json形式构造js对象
user4={name:"zhao",age:13,speak:function (){alert(this.name+" = "+this.age);}};
//工厂方式构造js类
function user5(){
tempuser=new user3();
tempuser.name="fanyunshuai";
tempuser.age=43;
return tempuser;
}
//js的单继承
function newuser(){
this.sex="man";
}
newuser.prototype=new user5();
//测试
function test(){
//newuser.prototype.speak();
var obj = new newuser();
obj.speak();
}
</script>
</head>
<body>
<input type="button" οnclick="test();" value="类实现测试" >
</body>
</html>
<head>
<script type="text/javascript">
//构造函数构造js类
function user1(){
this.name="fan";
this.age=23;
this.speak=function (){
alert(""+this.name+":"+this.age);
};
}
//原型构造js类
function user2(){}
user2.prototype.age=11;
user2.prototype.name="zhang";
user2.prototype.speak=function (){
alert(this.name+":"+this.age);
}
//原型、构造共同构造js类
function user3(){
this.name="kuang";
this.age=21;
}
user3.prototype.speak=function (){alert(this.name+":"+this.age);}
//json形式构造js对象
user4={name:"zhao",age:13,speak:function (){alert(this.name+" = "+this.age);}};
//工厂方式构造js类
function user5(){
tempuser=new user3();
tempuser.name="fanyunshuai";
tempuser.age=43;
return tempuser;
}
//js的单继承
function newuser(){
this.sex="man";
}
newuser.prototype=new user5();
//测试
function test(){
//newuser.prototype.speak();
var obj = new newuser();
obj.speak();
}
</script>
</head>
<body>
<input type="button" οnclick="test();" value="类实现测试" >
</body>
</html>