this refers to the object that calls the function. bind first argument is the value of this . Thus, function(data){...}.bind(an_object) can be read as "call this function, but set this inside the function to refer to an_object ". In the case of the React tutorial, an_object refers to the React component. So:
success: function(data) { this.setState({data: data}); }
this refers to an AJAX object. console.log(this) gives us
Object {url: "comments.json", type: "GET", isLocal: false, global: true, processData: true…}
success: function(data) { this.setState({data: data}); }.bind(this)
this refers to the React component. console.log(this) gives us
ReactCompositeComponent.createClass.Constructor {props: Object, _owner: null, _lifeCycleState: "MOUNTED", _pendingCallbacks: null, _currentElement: ReactElement…}
For further reading, Nicholas Zakas' book Object-Oriented Javascript explains in detail how bind works.
Keith yong
source share