日期:2014-05-16 浏览次数:20374 次
var obj = { key1: "hello" , key2: "world" }; function modifyObj(obj){ obj = { key3: "world1", key4: "hello1" }; //将不会改变外部的obj } function changeObj(obj){ obj.key3 = "world2"; obj.key4 = "hello2"; //将改变外部的obj对象的属性 } obj //函数调用前obj属性 Object key1: "hello" key2: "world" __proto__: Object modifyObj(obj) obj //函数调用后obj属性没有变化 Object key1: "hello" key2: "world" __proto__: Object changeObj(obj) obj //函数调用后,属性发生了变化 Object key1: "hello" key2: "world" key3: "world2" key4: "hello2" __proto__: Object?