201511041227_《JavaScript——动态原型对象(优化写法)》
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('aa',34); console.log(xiaoYin.say()); //aa34我回来了~ var xiaoJuan = new Person('bb',36); console.log(xiaoJuan.say()); //bb36我回来了~
前端-语言