在此代码段中,删除返回 true。那么为什么删除后f调用成功了呢?
function X() {
this.f = function() {
console.log("X::f");
}
}
x = new X;
var f = x.f.bind(x);
console.log("delete: " + delete x);
f();
最佳答案
delete
只是删除了标识符 x
。该对象仍然存在于内存中,因为它绑定(bind)到 f
。
f
仍然引用具有相同绑定(bind)上下文的相同函数,即使 x
不是。
Unlike what common belief suggests, the delete operator has nothing to do with directly freeing memory (it only does indirectly via breaking references. See the memory management page for more details).
关于javascript - 绑定(bind)成员删除后调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30734833/