var name = "window";
const obj = {
name: "obj",
sayName: function () {
console.log(this.name);
},
};
obj.sayMyName = () => {
console.log(this.name);
};
const fn1 = obj.sayName;
const fn2 = obj.sayMyName;
fn1();
obj.sayName();
fn2();
obj.sayMyName();
依次输出:
window
obj
window
window
本次主要考察对this指向的理解,题目比较简单,不做具体的分析。
本答案由“前端面试题宝典”收集整理,PC端访问请前往: https://fe.ecool.fun/