用原型链的方式写一个类和子类

原型链的作用是用来实现继承,比如我们新建一个数组,数组的方法就是从数组的原型上继承而来的.
那么怎么用用原型链的方式写一个类和子类?

<script>
function Person(name,age){
this.name=name;
this.age=age;
}

Person.prototype.study=function(){
return "学习"
}

function Student(class_,name,age){
this.class_=class_;
this.name=name;
this.age=age;
}

Student.prototype=new Person();

 var s1=new Student("二班","王婷",18);
 console.log(s1.name,s1.age,s1.class_,s1.study());

</script>
5640239-ded3b77b9b37b756.jpg
图片发自简书App
原文地址:https://www.cnblogs.com/wangting888/p/9701908.html