1.对象在原型里作为属性的时候也是保持引用的
function Person (){ } Person.prototype.sex = "woman" Person.prototype.phone = {tel:1258444}; var li = new Person(); li.phone.tel=5854444; li.sex = "man" var wang = new Person(); console.log(wang.phone); //5854444 console.log(wang.sex); //woman
2.如果属性是一个对象的话,可以这样存储,每次实例化都会重新申请属性
function Person (){ this.phone={tel:1258444} } var li = new Person(); li.phone.tel=5854444; var wang = new Person(); console.log(wang.phone); //125844
3.原型只是在属性查找或方法调用时触发.
function Person (){ } Person.prototype.sex = "woman" Person.prototype.phone = {tel:1258444}; var li = new Person(); li.phone={tel:555555555}; //这个时候会把phone作为属性赋值.不会使用到原型链 var wang = new Person(); console.log(wang.phone); //1258444