var collection = { "5439": { "album": "ABBA Gold"
}
};function updateRecords(id, prop, value) {
collection1 = collection; document.write("begin "+JSON.stringify(collection)+"</br>");
collection1[id][prop]=value; document.write(JSON.stringify(collection1)+"</br>");
}
updateRecords(5439, "tracks", "Addicted to Love");
updateRecords(5439, "test", "my test");為何結(jié)果是begin {"5439":{"album":"ABBA Gold"}}"5439":{"album":"ABBA Gold","tracks":"Addicted to Love"}}
begin {"5439":{"album":"ABBA Gold","tracks":"Addicted to Love"}}
{"5439":{"album":"ABBA Gold","tracks":"Addicted to Love","test":"my test"}}不是begin {"5439":{"album":"ABBA Gold"}}
{"5439":{"album":"ABBA Gold","tracks":"Addicted to Love"}}
begin {"5439":{"album":"ABBA Gold"}}
{"5439":{"album":"ABBA Gold","test":"my test"}}collection是全局變量,我在函數(shù)里面也僅僅是對局部變量collection1賦值,collection1的改變,為何影響到了collection?
全局變量的值為何被改變了?
Smart貓小萌
2018-09-13 18:09:05