React 使用ES6+语法时 事件绑定疑惑


在使用React中 如果使用ES6的Class extends写法 如果onClick绑定一个方法 需要bind(this),
而使用React.createClass方法 就不需要.
请问这是为什么呢

reactjs es6

unine 9 years, 9 months ago

看这里:
图片描述

zwei666 answered 9 years, 9 months ago

React自动绑定
Autobinding: When creating callbacks in JavaScript, you usually need to explicitly bind a method to its instance such that the value of this is correct. With React, every method is automatically bound to its component instance. React caches the bound method such that it's extremely CPU and memory efficient. It's also less typing!

英俊小猛男 answered 9 years, 9 months ago

Your Answer