基元按值传递,对象按“引用副本”传递。
具体来说,当您传递对象(或数组)时,您(无形中)传递了对该对象的引用,并且可以修改该对象的 内容
,但是如果您尝试覆盖该引用,则不会影响该对象的副本。调用者持有的引用-即引用本身通过值传递:
function replace(ref) { ref = {};// this pre does _not_ affect the object passed}function update(ref) { ref.key = 'newvalue'; // this pre _does_ affect the _contents_ of the object}var a = { key: 'value' };replace(a); // a still has its original value - it's unmodfiedupdate(a); // the _contents_ of 'a' are changed


