I would have thought that console.log(myCounting.value);
would actually print 7
because the add method got invoked twice (see comments) . However it prints 6
. Is that because of the scope? Meaning that invoking the 'invoking' function with myCounting.add
doesn't change the value because its a different scope? Could someone explain as I'm learning scopes..Thanks!!
function Counting(){
this.value = 5;
}
Counting.prototype.add = function(){
this.value++;
}
var myCounting = new Counting();
myCounting.add(); // invoked once
function invoking(funcs){
funcs();
}
invoking(myCounting.add); //invoked twice
console.log(myCounting.value);