Why is the value for "o.value" unchanged when changer(o.inc) is called?
Fiddle: http://jsfiddle.net/illumine/qbr9xupt/
function customobject(){
this.value = 2;
}
customobject.prototype.inc = function(){
this.value++;
}
function changer(func){
func();
}
var o = new customobject();
alert(o.value); // o.value = 2
o.inc();
alert(o.value); // o.value = 3
changer(o.inc);
alert(o.value); // Still 3 why not 4
thisis not what you think it is. Tryalert(this);just beforethis.value++and you'll see.