js如何实现继承
(通过对象冒充来实现的继承)
<script>
function Stu(name,age){
this.name = name;
this.age = age;
this.show = function () {
window.alert("公共类")
}
}
//实现继承(通过对象冒充来实现的继承)
function MidStu(name,age){
this.stu = Stu;
this.stu(name,age);//这句必须写,js是通过对象冒充来实现的继承(因为js是动态语言,如果不执行,则不能实现继承效果)
}
var midStu = new MidStu("xxc","22");
midStu.show();
</script>
