Yet another setInterval & this not working
<p>I have a problem with <code>this</code> and <code>setInterval</code> in JavaScript. I read a couple of solutions here on SO but couldn't make them work for me. Here is my code:</p>

<pre><code>var timer_func = function(){
    var that = this;
    var inspect = function(clusters){

        var clength = "";

        for(var i = 0; i &lt; that.clusters.length; i++){   //---&gt; undefined that.clusters.length
            clength += that.clusters[i].processes.length + ",";
        }

        console.log(clength);
    }

    var inspector = setInterval(inspect, 1000);
};
//much later
timer_func();
</code></pre>

<p>I am 100% I initialize what here is called <code>this.clusters</code> in my code before calling <code>timer_func()</code> but still apparently the variable that I try to access is undefined (whereas if I print it somewhere else outside the timeout is not). Any suggestion? Thanks.</p>
