Javascript 请解释下图中的行为

Javascript 请解释下图中的行为,javascript,Javascript,有人能解释这种行为吗?这是由于“this”关键字在使用它的不同上下文中的行为造成的 下面是这个关键字的完整参考 请发布您的代码而不是图片,请参考此。这是否回答了您的问题? var foo = { bar : function(){ console.log(this); // For your reference return this.baz; }, baz: 1 }; (function(v){


有人能解释这种行为吗?

这是由于“this”关键字在使用它的不同上下文中的行为造成的

下面是这个关键字的完整参考


请发布您的代码而不是图片,请参考此。这是否回答了您的问题?
var foo = {  
    bar : function(){ 
            console.log(this); // For your reference
            return this.baz;  
          },
    baz: 1
};

(function(v){
    console.log(typeof arguments[0]()); // In this context "this" keyword refers to the current function "bar" and not the parent foo object, As the current function doesn't contain baz it returns undefined
    console.log(typeof foo.bar());  // In this context "this" keyword refers to its parent "foo" Object so this.baz will be refer to foo.baz and typeof 1 is a number
    console.log(typeof v()); // Here "this" keyword refers to the window object hence this.baz will refer to window.baz which is undefined
    return typeof arguments[0]();
})(foo.bar);