var obj={hello:1, world:2}; var fn = function(o){ var ref =o; console.log(ref); ref.good ="good"; }
fn(obj); fn(obj);
chrome 控制台输出为 :
Object {hello: 1, world: 2} Object {hello: 1, world: 2, good: "good"}
为什么两次输出不一样呢?
6 回复
var obj={hello:1, world:2}; var fn = function(o){ var ref =o; console.log(ref); ref.good ="good"; }
fn(obj);//只调用一次
chrome 控制台输出为 :
Object {hello: 1, world: 2, good: "good"}