原型继承例子,看各自的prototype和constructor
2016-07-28 22:04
267 查看
<script> function superF(){ this.sup = true; } superF.prototype.getSuperValue = function(){ return this.sup; } function sub(){ this.subProperty = false; } sub.prototype = new superF(); var instance = new sub(); // console.log(superF); console.log(superF.prototype); //getSuperValue console.log(sub.prototype); //sup,subProperty console.log(instance.constructor); //superF console.log(sub.prototype.constructor); //superF </script>
三层继承:
<script> function SuperType(){ this.color=["red","blue","green"]; this.name='Ant'; } SuperType.prototype.showSuper = function(){ console.log(this.name); } function MidType(){ this.age = 10; } MidType.prototype.showMid = function(){ console.log(this.age); } function SubType(){ this.type='js'; } MidType.prototype = new SuperType(); SubType.prototype = new MidType(); var instance_s1 = new SubType(); var instance_m1 = new MidType(); console.log("SuperType.prototype:------------------------------------------------"); console.log(SuperType.prototype); //见执行结果图 console.log("MidType.prototype:----------------------------------------------------") console.log(MidType.prototype); //见执行结果图 console.log("SubType.prototype:-----------------------------------------------------"); console.log(SubType.prototype); //见执行结果图 </script>
相关文章推荐
- prototype Element学习笔记(篇一)
- Prototype 学习 工具函数学习($方法)
- Prototype使用指南之selector.js说明
- prototype1.4中文手册
- prototype 1.5相关知识及他人笔记
- prototype Element学习笔记(Element篇三)
- PostgreSQL教程(三):表的继承和分区表详解
- prototype Element学习笔记(篇二)
- Lua面向对象之类和继承浅析
- 浅析Ruby中继承和消息的相关知识
- prototype 的说明 js类
- Prototype 学习 工具函数学习($A方法)
- Prototype源码浅析 String部分(三)之HTML字符串处理
- javascript prototype,executing,context,closure
- prototype 1.5 & scriptaculous 1.6.1 学习笔记
- prototype 学习笔记整理
- 设计引导--一个鸭子游戏引发的设计理念(多态,继承,抽象,接口,策略者模式)
- javascript 原型继承介绍
- C++实现不能被继承的类实例分析
- C# 面向对象三大特性:封装、继承、多态