Skip to content
js
<script>
  class C1 {
    constructor() {
      window.setTimeout(function () {
        // 普通函数的this执行遵循谁调用指向谁的原则
        console.log(this)
      })
      window.setTimeout(() => {
        // 箭头函数没有this,会向上找this
        console.log(this)
      })
    }
  }
  new C1()
</script>

Last updated: