Assigning a value to a object's property/variable in a callback
<pre><code>var obj1={
    var1:"val1",
    init:function(){
        this.var1="val2";
        var self=this;
        setTimeout(function(){self.var1="val3"},1);
        setTimeout(function(){obj1.var1="val3"},1);
    }
}

obj1.init();
console.log(obj1.var1);
console.log(obj1);
</code></pre>

<p>How to set/assign a value to var1 in the setTimeout callback. Assigning val3 does not have an effect and as seen in the screenshot we have two properties mentioned as var1 now. 1 is var1=val2 and other is var1=val3 , but this.var1 always returns val2 not val3</p>

<p><img src="http://i.stack.imgur.com/NXYdh.jpg" alt="enter image description here"></p>
