js中用prototype实现继承
js中用prototype实现继承
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
//prototype 模拟继承
function Person(name,age){
this.name=name;
this.age=age;
}
function Student(){
this.stuId=2222222;
}
Student.prototype=new Person("zhangsan",20);
var stu=new Student();
alert(stu.name);
alert(stu.age);
</script>
</head>
<body>
</body>
</html>
阅读更多
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: JS关于prototype的几点
- 下一篇: js中的prototype