In this snippet delete returns true. So why f is being successfully called after delete?
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 just removed the identifier x. The object still exists in memory, because it is bound to f.
f still refers to the same function with the same bound context, even though x doesn't.
See the MDN page on delete:
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With