Associated call participant after deletion

In this snippet, delete returns true. So why is f being successfully called after deletion?

function X() {
    this.f = function() {
        console.log("X::f");
    }
}

x = new X;
var f = x.f.bind(x);
console.log("delete: " + delete x);
f();
      

Run codeHide result


+3


source to share


1 answer


delete

just removed the id x

. The object still exists in memory as it is bound to f

.

f

still refers to the same function with the same associated context, though x

doesn't work.



See MDN's page atdelete

:

Contrary to what popular belief suggests, the delete operator has nothing to free memory directly (this is only indirectly related to link breaking. See the memory management page for details).

+5


source







All Articles