var name = 'The window';
(function () {
var name = 'wgm';
console.log(this.name); //'The window'
(function () {
var name = 'wm'
console.log(this.name); //'The window'
(function () {
var name = 'w'
console.log(this.name); //'The window'
var obj1 = {
name: 'obj1',
test(callback) {
console.log(this.name); //'obj1'
callback();
}
}
var obj2 = {
name: 'obj2',
sayThis() {
console.log(this.name); //'The window'
return this.name;
}
}
console.log(
obj1.test(obj2.sayThis) //undefined 为什么会输出这样的结果??
);
})();
})();
})();
因为obj1.test 没有return,默认返回 undefined