function f(o) {
o.message = "set in f";
o = {
message: "new object!"
};
console.log(`inside f: o.message="${o.message}" (after assignment)`);
}
let o = {
message: 'initial value'
};
console.log(`before calling f: o.message="${o.message}"`);
f(o);
console.log(`after calling f: o.message="${o.message}"`);
如果运行此示例,您将看到:
before calling f: o.message="initial value"
inside f: o.message="new object!" (after assignment)
after calling f: o.message="set in f"
我正在阅读学习javascript的书,而且我不理解这段代码,尤其是console.log中的代码确实令人困惑。
谢谢。