第六章:在创建对象的方式中有这样一种动态原型模式
function Persion() { this.name="wyq"; this.friends=["a", "b", "c"]; //下面的代码有什么意义??? 每次new一个对象的时候肯定要执行里面的函数啊
if(typeof this.sayName !=="function"){ this.sayName = function () { console.log("friends",this.friends);
}
}
}直接这样写不就好了吗?
function Persion() { this.name="wyq"; this.friends=["a", "b", "c"];
}
Persion.prototype = { sayName: function () { console.log("this.name", this.name);
},
};
米琪卡哇伊
慕工程0101907
随时随地看视频慕课网APP
相关分类