I have a small code snippet below
var foo = {
bar: function () {
return this.baz;
},
baz: 1
};
(function () {
return typeof arguments[0]();
})(foo.bar);
baz = 1;
when the function is executed foo.bar, it thisrefers to the region of the window, which, of course, knows nothing about baz, so I defined baz=1in the window. but the program still does not work and returns undefined. why it returns undefined, but bazdetermined in the window, and I execute foo.bar from the window
source
share