In javascript I do:
var myObject = {
myBoo: false,
myMethod: function () {
console.log("my method: "+ myBoo);
}
}
console.log("myObject.myBoo=" + myObject.myBoo);
myObject.myMethod();
This outputs:
myObject.myBoo=false
ReferenceError: myBoo is not defined
Why is myBoo undefeind from myMethod’s perspective?
Thanks.
This is because myBoo is not defined as a global variable, but rather as an object property. The proper way of accessing it in the
myMethodfunction would therefore be: