How to have an instance delete itself from within a prototype function is JavaScript
<p>If I have a JavaScript constructor function, and I set a destroy method on its prototype. Is it possible to delete (or at least unset) the instance from the destroy method? Here's an example of what I'm trying to do.</p>

<pre><code>Klass.prototype = {
  init: function() {
    // do stuff
  },
  destroy: function() {
    // delete the instance    
  }
};

k = new Klass
k.destroy()
console.log(k) // I want this to be undefined
</code></pre>

<p>I understand that I can't simply do <code>this = undefined</code> from with the destroy method, but I thought I could get around that by using a timeout like so:</p>

<pre><code>destroy: function() {
  var self = this;
  setTimeout( function() {
    self = undefined
  }, 0)  
}
</code></pre>

<p>I thought the timeout function would have access to the instance via <code>self</code> from the closure (and it does), but that doesn't seem to work. If I <code>console.log(self)</code> from inside that function it shows up as <code>undefined</code>, but <code>k</code> in the global scope is still an instance of <code>Klass</code>.</p>

<p>Does anyone know how to make this work?</p>
