<html>
<head>
<script language = "javascript" type="text/javascript">
//javascript中对象的继承
function Stu(name,age){
//公有属性
this.name = name;
this.age = age;
//公有方法
this.show = function(){
window.alert(this.name+this.age);
}
}
//继承的使用
function Midstu(name,age){
this.stu = Stu;//js中是通过对象冒充来实现继承的。
this.stu(name,age);
}
//创建一个对象
var stus = new Midstu('张三',20);
stus.show();
</script>
</head>
</html>
继承
最新推荐文章于 2024-11-27 09:51:35 发布