0

I have an object with a method, destroy:

let object = {
    destroy() {
        handleDestroy.call(null, this);
    }
}

function handleDestroy(obj) {
    obj = null;
}

I know that technically the object is not destroyed even if it did work, but I am wondering why I can't reassign objects to null or other types of objects this way? When I call handleDestroy with the object as a parameter, or if I invoke the destroy method, object remains unchanged.

James Hamann
  • 842
  • 6
  • 12
  • You’re just reassigning the parameter. It’s like reassigning a variable—it doesn’t change the value. – Sebastian Simon Aug 28 '19 at 20:20
  • 1
    Parameters are passed by value, not by reference. Assigning to `obj` just assigns to the local variable, not the caller's variable. Also, it's not possible to assign anything to `this`, it's not a real variable. – Barmar Aug 28 '19 at 20:20
  • Looks like I need to do some more reading on this. Thanks everyone – James Hamann Aug 28 '19 at 20:24

0 Answers0