您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

JS混合继承详解

2026/1/8 1:38:24发布19次查看
本文主要和大家分享js混合继承详解,希望能帮助到大家。
<script type="text/javascript"> window.onload=function(){ //混合继承:原型实现继承+借用构造函数继承 function person(name,age,gender,wight){ this.name=name; this.age=age; this.gender=gender; this.wight=wight; } person.prototype.sayhi=function(){ console.log("欢迎!"); } function student(name,age,gender,wight,score){ person.call(this,name,age,gender,wight);//实现属性继承 this.score=score; } student.prototype=new person();//实现方法继承 student.prototype.sleep=function(){ console.log("请保证充足睡眠!"); } var stu=new student("lll",20,"male",150,100); console.log(stu.name,stu.age,stu.gender,stu.wight,stu.score); stu.sayhi(); stu.sleep(); var stu2=new student("222",22,"female",100,110); console.log(stu2.name,stu2.age,stu2.gender,stu2.wight,stu2.score); stu2.sayhi(); stu2.sleep(); } </script>
以上就是js混合继承详解的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product