继承案例

来源:互联网 发布:模架编程招聘 编辑:程序博客网 时间:2024/05/21 21:52
<span style="font-size:18px;"><!DOCTYPE html><html> <head>  <title> new document </title>  <meta charset="utf-8" /><script>//飞行物的构造函数function Flyer(fname,speed){//this->a380this.fname=fname;this.speed=speed;}Flyer.prototype.fly=function(){console.log(this.fname+" 以时速 " +this.speed+" 飞行");}//飞机 是 飞行物function Plane(fname,speed,capacity){//this->a380//Flyer.call(this,fname,speed);//借用父类型构造函数Flyer.apply(this,arguments);//fname和speed自有属性this.capacity=capacity;}//设置继承: Plane.prototype继承Flyer.prototypeObject.setPrototypeOf(Plane.prototype,Flyer.prototype);var bird=new Flyer("小麻雀",50);//bird.__proto__=Flyer.prototype//console.log(bird);bird.fly();var a380=new Plane("A380",1000,555);//a380.__proto__=Plane.prototype//console.log(a380);a380.fly();</script> </head> <body>   </body></html></span>

0 0