继承案例
2016-03-15 23:17
357 查看
<span style="font-size:18px;"><!DOCTYPE html> <html> <head> <title> new document </title> <meta charset="utf-8" /> <script> //飞行物的构造函数 function Flyer(fname,speed){ //this->a380 this.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.prototype Object.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>
相关文章推荐
- 项目4:换硬币
- redis常见的几种使用场景
- git创建项目并上传代码
- Node.js入门
- Java静态变量,常量,成员变量,局部变量
- 第三百四十八天 how can I 坚持
- AngularJS中的$apply
- 思科网络设备模拟器GNS3与SecureCRT关联
- synchronized 方法与锁对象
- 20 个 CSS 高级技巧汇总
- python学习之常用的内置类(4):python中的XML
- Android 防内存泄露handler
- poj 1804 Brainman(归并排序求逆序对)
- 经典算法练习
- /* 判断一个对象是不是数组*/
- 【Android开发】greenrobot三大开源利器详解(一)——EventBus
- Leetcode #12 & #13 Integer to Roman & Roman to Integer 解题小节
- LINQ查收数据库的性能瓶颈
- 前端调试
- hadoop 2.7.2开发环境配置