1.分别对实例的name赋值,并没有涉及到原型的name属性
var fun = function(){} fun.prototype.name='peter'; var a = new fun(); var b = new fun(); a.name = 'jack'; b.name = 'tom'; console.log(a.name); //jack console.log(b.name); //tom
2.第一步在实例没有找到info属性,根据原型链往上找到了原型的info属性,然后给原型的info的name属性赋值
var fun = function(){} fun.prototype = { info : { name : 'peter', age : 25 } } var a = new fun(); var b = new fun(); a.info.name = 'jack'; b.info.name = 'tom'; console.log(a.info.name); //tom console.log(b.info.name); //tom