I'd like to know how to delete an object from inside, when this object will no longer be used.
For example :
var MyObject = function () {
return {
'some': function() {...},
'actions': function() {...},
'destroy': function() {
this = null; // throws a "ReferenceError: Invalid left-hand side in assignment"
},
}
}
// Doing so, I would be able to :
var obj = new MyObject();
obj.some();
// And when I have finished :
obj.destroy();
The reason behind that is that I can't destroy it from outside (the object is created on "click" on a DOM element, but it will be destroyed when you click somewhere else, so the scope of the creation (in the "onClick" method) is not available where I want to delete it.
How can I do that?
delete this