I am learning React.js .In the tutorial the author use onClick with bind , but at some places he do not use the bind with the onClick. I can not get the difference between the two.
<button onClick={this.handleAdd}>Add Item</button> You might use bind in order to pass in a certain argument to the handler method.
For example:
render: function() { return _.map(list, function(item) { return <li onClick={this.clickItem.bind(this, item)}>{item.name}</li>; }); }, clickItem: function(item, event) { //do something with the clicked item } If you don't need to inject an argument, you don't need to bind since react always calls the handler method in the scope of the component - although this is changing soon
bind method: developer.mozilla.org/en/docs/Web/JavaScript/Reference/…React.Component existed (actually yeah, I reference the "coming change" in my answer). Back then, you always used React.createClass(), which meant that this.handleAdd would always be bound to the component instance, and you would never use bind unless you had an argument to pass. I guess you could override this if you wanted to, but that would've been really odd to do for a component's method.
bindmethod?