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