javascript创建对象之动态原型模式(五)

 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                 }
 8             }
 9         }
10         var man =new Human ("凯撒", "男");
11         man.say();

 

posted @ 2014-03-26 09:17  思思博士  阅读(117)  评论(0编辑  收藏  举报