What is the appropriate way to destroy an instance of a "class" in JavaScript? I'm using node to "require" my classes and its prototypes. And I noticed, setting the instance of the class to equal null
does not seem to actually destroy the instance.
E.g.:
The class
function coolClass(){
this.bob = 'Hey, this is Bob. I should be destroyed, right?!';
this.init();
console.log('Cool class has been initialized!');
}
coolClass.prototype.init = function(){
var self = this;
this.culprit = setInterval(function(){
console.log(self.bob);
},1000);
}
exports.coolClass = coolClass;
Creating & attempting to destroy instance
var coolClass = require('coolClass');
var instance = new coolClass();
setTimeout(function(){
instance = null;
},5000);
My expectations were that once the timer's function was ran, the coolClass
instance would be destroyed; however, it seems that I am wrong.
Any ideas on how to completely remove the instances?
Thanks!