摘要: 1 function Father() { 2 this.fatherValue = "爸爸"; 3 } 4 Father.prototype.getFatherValue = function () { 5 return this.fatherValue 6 } 7 function Son() { 8 this.sonValue = "儿子"; 9 }10 Son.prototype = new Father();11... 阅读全文
posted @ 2014-03-11 15:57 思思博士 阅读(267) 评论(0) 推荐(0) 编辑
摘要: 所谓稳妥对象,指的是没有公共属性,而且其方法也不引用this的对象.稳妥对象最适合在一些安全的环境中(禁止使用this和new)或者在防止数据被其他应用程序改动时.稳妥构造函数模式有2个特点:1.新创建对象的实例方法不引用this;2.不使用new操作符调用构造函数.1 function createHuman(name, sex) {2 var obj = new Object();3 obj.say = function () {4 alert(name);5 }6 }7... 阅读全文
posted @ 2014-03-11 10:48 思思博士 阅读(371) 评论(0) 推荐(0) 编辑
摘要: 这种模式的基本思想是创建一个函数,该函数的作用仅仅是封装创建对象的代码,然后再返回新创建的对象;但是从表面上看,这个函数有很像典型的构造函数. 1 function createHuman(name,sex) { 2 var obj = new Object(); 3 obj.name = name; 4 obj.sex = sex; 5 obj.say = function () { 6 alert(this.name); 7 } 8 ... 阅读全文
posted @ 2014-03-11 10:30 思思博士 阅读(350) 评论(0) 推荐(0) 编辑
摘要: 动态原型模式是将所有的信息都封装到工造函数中,而构造函数中初始化原型,有保持了同时在使用构造函数和原型的优点.1 function Human(name, sex) {2 this.name = name;3 this.sex = sex;4 if (typeof this.say != "function") {5 Human.prototype.say = function () {6 alert(this.name);7 ... 阅读全文
posted @ 2014-03-11 09:32 思思博士 阅读(823) 评论(3) 推荐(2) 编辑