第一种模式:

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

本文作者:罗坚元

最新文章

  1. ASP.NET MVC——模型绑定
  2. maxscale
  3. lkx开发日志1-项目前的准备
  4. text-indent无效解决方案
  5. Apache索引目录浏览的学习笔记
  6. Ajax提交后台中文乱码问题
  7. [Google Translation API v2 for Java]
  8. POJ 2418 Hardwood Species
  9. OC中修饰符:宏define 常量:const extern
  10. [MySQL] 同步一张表、复制过滤设置
  11. Office2016 转换零售版为VOL版
  12. UESTC_秋实大哥与快餐店 2015 UESTC Training for Data Structures<Problem C>
  13. 201521123080《Java程序设计》第9周学习总结
  14. Query DSL(1)
  15. CentOS6.x机器安装Azure CLI2.0【1】
  16. pssac plot
  17. cocoapods卸载与安装
  18. Simple2D-26 Simple2D 最后的工作,开发结束
  19. istview android:cacheColorHint,android:listSelector属性作用(转)
  20. Spring中的注解配置-注入bean

热门文章

  1. iOS学习笔记01-APP相关
  2. NOJ——1274The battle of Red Cliff(并查集按秩合并)
  3. HDU——4565So Easy!(矩阵快速幂)
  4. 解决v-for产生的警告的办法
  5. spring boot-html和templates
  6. bzoj 2300 [HAOI2011]防线修建 set动态维护凸包
  7. 【HDOJ5974】A Simple Math Problem(构造,解方程)
  8. WebRTC VoiceEngine综合应用示例(一)——基本结构分析(转)
  9. 【Visual Studio】error C2220: 警告被视为错误 - 没有生成“object”文件 (转)
  10. http协议相关面试题