score:2

Accepted answer

because of the variable scoping on javascript. since you're inside a function there, like that:

success: function(data) {
        this.setstate({data: data});
      }

your "this" will refer to the scope inside the success function. when you do a .bind(this) after the function, it tells the js that you want to use the outer reference for this. in your case, the scoping for the outer function "loadcommentsfromserver"

also i'd recomend you further reading: http://javascriptissexy.com/javascript-apply-call-and-bind-methods-are-essential-for-javascript-professionals/

http://www.smashingmagazine.com/2014/01/23/understanding-javascript-function-prototype-bind/

score:1

the bind method allows you to change the context of a function.

here is a little example to understand bind()

var mypie = {
  love : 'full'
};

function doilove(){
  console.log(this.love);
}

doilove(); // returns undefined
doilove().bind(mypie); // returns 'full'

actually, your code is to call the this.props.url url, we expect json data from the server, if we success we execute the success function, else if we failed we execute the error function.


Related Query

More Query from same tag