Killing setInterval upon object deletion
<p>I have the following HTML page:</p>

<pre><code>&lt;html&gt;
&lt;script&gt;
   var global = {};
   global.obj = {
      // when called this function will cause 'hello' to be output to the
      // console every 1 second
      repeat: function () {
         setInterval(function () {
            console.log('hello');
         }, 1000);
      }
   }

   global.obj.repeat();
   global.obj = [];

   // even after we overwrite global.obj, 'hello' 
   // continues to be output to the console every second
&lt;/script&gt;
&lt;/html&gt;
</code></pre>

<p>I want to write a function similar to repeat, except when global.obj is overwritten, setInterval will stop being called</p>
