var a = 'Oops, global!';
function foo () {
console.log('打印a:'+this.a);
}
let obj2 = {
a: 2,
foo: foo
};
let obj1 = {
a: 22,
obj2: obj2
}
obj2.foo(); // 2
obj1.obj2.foo(); // this指向最后一层调用函数的对象
let bar = obj2.foo;
bar();
function test fn){
fn();
}
test(obj2.foo)