Js

bind this(this in js is not bound)

复习一下 react 为什么需要 bind this
image.png
原因在于实例方法(普通函数)在传递中会丢失应该的(应该为组件实例) this 指向
因为普通函数的 this 是调用期才能决定的,如果没有调用方(如果用 bind 绑定了调用方,也就是 this,那之后的 this 就能正常取到),那调用方的默认是 global,严格模式下会直接为 null 抛错。
https://javascript.info/object-methods#this-is-not-bound
image.png
Js 原生的 this 就是非绑定的,class 中的 箭头函数定义 应该就是个语法糖。