在 React 中,使用 const function = () => {}
和 function () {}
的差别在于箭头函数和普通函数的 this 的指向不同。
箭头函数的 this 是固定的,指向外层作用域的 this,而普通函数的 this 可以动态绑定,由函数调用的方式决定。
如果你在 React 中使用 const function = () => {}
定义了一个箭头函数,那么使用 this.function
在别处是不能被调用的。因为箭头函数不能作为对象的方法,所以不能通过 this 来访问。
如果你使用 function () {}
定义了一个普通