原型链的作用是用来实现继承,比如我们新建一个数组,数组的方法就是从数组的原型上继承而来的.
那么怎么用用原型链的方式写一个类和子类?
<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>
福利一:前端,Java,产品经理,微信小程序,Python等资源合集大放送:https://cloud.tencent.com/developer/article/1141313
福利二:微信小程序入门与实战全套详细视频教程

原文作者:祈澈姑娘
原文链接:https://www.jianshu.com/u/05f416aefbe1
创作不易,转载请告知
90后前端妹子,爱编程,爱运营,爱折腾。