普通函数内部,谁调用的函数,this 就指向谁
var User = {
count:1,
action: {
getCount:function () {
console.log('this',this)
return this.count;
}
}
};
var getCount= User.action.getCount;
setTimeout(() => {
console.log('result 1', User.action.getCount());
})
console.log('result 2', getCount());
//输出
'this', window
result 2 undefined
'this', {getCount: ƒ}
result 1 undefined