Is there any way that I can define a destructor for an object in JavaScript that will be called automatically when object is discarded?
Im creating my obj like so:
function SomeObject(){
this.test = null;
this.method = function(){
alert("Testing Method");
};
this.destroy = function(){
// Destroy stuff here
};
}
var test = new SomeObject();
I can call destroy when needed but when the user exits the page I cant call destroy. The reason I need to do this is that I call functions in php using ajax that saves session data. I would like it to destroy the particular session data when im done with that particular js object.
Any ideas?