首页 > 编程语言 > 详细

201511041227_《JavaScript——动态原型对象(优化写法)》

时间:2015-11-04 13:12:54      阅读:246      评论:0      收藏:0      [点我收藏+]
function Person(userName ,age){
    this.userName = userName ;
    this.age = age;
    this.family = [‘爸爸‘,‘妈妈‘,‘姐姐‘,‘老婆‘];
    if(typeof this.say !== ‘function‘){
    Person.prototype.say = function(){
        return this.userName + this.age + ‘我回来了~‘;  
         };
    }
};

var xiaoYin = new Person(‘殷敏峰‘,34);
console.log(xiaoYin.say());  //殷敏峰34我回来了~

var xiaoJuan = new Person(‘殷敏娟‘,36);
console.log(xiaoJuan.say());  //殷敏娟36我回来了~

 

201511041227_《JavaScript——动态原型对象(优化写法)》

原文:http://www.cnblogs.com/beesky520/p/4935608.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!