JavaScript2种构造函数创建对象的模式以及继承的实现
2015-06-07 12:25
1161 查看
第一种模式:
根据第一种模式说一下继承的实现:
第二种模式:
第二种模式的继承:
本文作者:罗坚元
function Person(){ } Person.prototype.say=function(){ alert('hello'); } var person=new Person(); person.say();//hello
根据第一种模式说一下继承的实现:
function Person(){ } Person.prototype.say=function(){ alert('hello'); } function Man(){} Man.prototype=new Person() var man=new Man(); man.say(); //hello
第二种模式:
function Person(){ var _this={};//创建一个空的对象 _this.say=function(){alert('hello')}; return _this; } function person=new Person(); person.say();//hello
第二种模式的继承:
function Person(){ var _this={};//创建一个空的对象 _this.say=function(){alert('hello')}; return _this; } function Man(){ var _this=new Person(); return _this; } var a=new Man(); a.say();//hello
本文作者:罗坚元
相关文章推荐
- [Network] HTML、XML和JSON学习汇总
- javascript标签位置以及defer、async属性的区别
- 服务器端解决JS跨域调用问题
- EXTjs 提交的方式
- JSP复习
- JS结构图
- javascript操作ASP.NET服务器控件
- JavaScript OOP 创建对象的7种方式
- 使用JavaScript操作DOM节点元素的常用方法(创建/删除/替换/复制等)
- 控件调用javascript,先验证后提交.
- Javascript 数组函数
- javascript防止SQL注入
- 动态加载js文件
- javascript中对条件判断语句的优化
- javascript中对条件判断语句的优化
- javascript中对条件判断语句的优化 分类: JavaScript 2015-06-07 09:54 832人阅读 评论(2) 收藏
- javascript客户端检测技术
- JavaScript OOP 创建对象的7种方式
- 理解Javascript的动态语言特性
- JS放在head和放在body中的区别