https://time.geekbang.org/column/article/128427

this: 从js执行上下文的视角讲清楚this

背景:对象内部方法中使用对象内部的属性

注意:

1. 当函数作为对象的方法调用时,函数中的 this 就是该对象;

2. 当函数被正常调用时,在严格模式下,this 值是 undefined,非严格模式下 this 指向的是全局对象 window;

3. 嵌套函数中的 this 不会继承外层函数的 this 值。

4. 箭头函数没有自己的执行上下文,所以箭头函数的 this 就是它外层函数的 this。

三种this:

全局执行上下文中的this
函数执行上下文中的this
eval中的this

三种方式设置函数执行上下文中的this:

  1. call/bind/apply
  2. 对象调用
  3. 构造函数

https://github.com/mqyqingfeng/Blog/issues/7

执行结果/this指向

https://mp.weixin.qq.com/s/1KPGlsLlzKH2E8gpRZ1Rdg