this

 
💡
Notion Tip: Use this template to codify the process around a feature launch.
  • this 是和执行上下文绑定的
  • 执行上下文
      1. 全局执行上下文
      1. 函数执行上下文
      1. eval 执行上下文
       

全局执行上下文中的 this

  • 非严格模式, 指向 window 对象
  • 严格模式为 undefine
 

函数执行上下文的 this

 

设置执行上下文中的 this 指向

  1. 通过函数的 call 方法设置
  1. 通过对象调用方法设置
  1. 通过构造函数中设置
 

this 的设计缺陷以及应对方案