const base = { name: 'HAHA' }let ob = Object.create(base)
ob = {
showName() { console.log(this, this.name);
}, showNameArrow: () => { console.log(this, this.name);
}
}
ob.showName(); // Object{} undefinedob.showNameArrow(); // window{} ""第一个showName的this既然指向ob对象,但是this.name为什么不能通过原型向上查找到{name: 'HAHA'},而是undefined呢?
第二个showNameArrow是因为我不知道在对象里如何写箭头函数:
是不是在对象里面因为不涉及块级作用域,就没有必要写箭头函数?
但是如果要写,应该怎么写?
我这种写法的箭头函数为什么指向全局?
相关分类