1var name = 'window' 2const obj = { 3 name: 'obj', 4 sayName:function() { 5 console.log(this.name) 6 }, 7} 8obj.sayMyName = () => { 9 console.log(this.name) 10} 11const fn1 = obj.sayName 12const fn2 = obj.sayMyName 13fn1() 14obj.sayName() 15fn2() 16obj.sayMyName()
参考答案:
依次输出:
window
obj
window
window
本次主要考察对this指向的理解,题目比较简单,不做具体的分析。
本答案由“前端面试题宝典”收集整理,PC端访问请前往: https://fe.ecool.fun/
最近更新时间:2022-04-10