Im wondering how to properly "Clear" a object instance. With the code below, the internal setInterval() will continue to run even after the instance is "cleared" by the parent.
// simple Class
var aClass = function(){
    return {
        init: function(){
            console.log("aClass init()")
            setInterval( this.tick, 1000 );
            // note: we're not storing the ref
        },
        tick: function(){
            console.log("aClass tick");
        }
    }
}
// instantiate the class
var inst = new aClass();
inst.init();
// try to forget the instance
function test(){
    console.log("test() 1 inst:", inst);
    inst = null;
    console.log("test() 2 inst:", inst);
}
// run for a while, then call test()
setTimeout( test, 4000 );
Output:
aClass init()
aClass tick
aClass tick
aClass tick
test() 1 inst: {.....}
test() 2 inst: null
aClass tick
aClass tick ...
Problem is that the "aClass tick" message continues to print after the test().
Ideas?
 
     
     
     
     
     
    