Lets take an object
var o = {a : 10 ,b:20,f:function(){ return this.a + this.b; }};
console.log(o.f())//30 works as expected
Now,
var o = {a:10,b:20,f:function(){ return this.a + this.b; }};
var p = o;
p.a = 1;
p.b = 4;
console.log(p.f()); // 5 works fine
console.log(o.f()); //5,it should 30 right but why it is showing 5
why is it working like this. If i do o.f() it should get the value from object o.
It looks like i have not understood the bind properly
console.log(o.f.bind(o)())//gives 5
console.log(o.f.bind(this)())//gives 30
please give the difference between these two lines codes.
ochanged already .console.log(o.f.bind(this)), what isthis?o.f.bind(this)()