In the code below, why does console.log(myObject.obj1 ) display a proto object in the console instead of actual object data? Meanwhile, I can see the obj1 data using console.log(myObject).
$(function () {
var myObject = {
obj1: {},
}
$.ajax({
url: "foobar.json",
success: function (data) {
myObject.obj1 = data.obj1;
}
});
console.log(myObject); // displays myObject data in console!
console.log(myObject.obj1 ) // displays a __proto__ object :(
});
If this is related to async code, why does console.log(myObject) work? Maybe this is related to scope, i.e. myObject.obj1 being out of scope?