有没有办法通知参考更改?
我觉得我需要清楚我的意思:
var a = { aa: 1 };
a = { aa: "allowed" }; // `a`'s reference was modified
a.aa = "foo"; // `a` was mutated, but the reference was not modified. Don't care.
这是我感兴趣的参考变化。在 Swift 中,这是一个didSet
块。我想观察指向的参考的变化a
。
完整示例:
var reel = [];
function print(message) {
reel = reel.concat([message]); // non-mutating push changes "reel" reference to this new object.
}
Object.SOME_FUNCTION(reel, onChangeReel); // not a real function
function onChangeReel() { /* update the DOM */ }