Why do not use {this.renderTasks.bind(this)}?


#1

In Simple Todo App sample https://github.com/meteor/simple-todos-react/commit/716c4acbf54ecdf0438a4995f2441f73c608586b , Line 29, why do not use {this.renderTasks.bind(this)} ?

I thought in ES6, we need to use {this.renderTasks.bind(this)} ? instead of {this.renderTasks()}


#2

When you bind the function to the ‘this’ context, you are not running the function, just “preparing” it to be run at a later stage with your given context. This is not what we are after in this case, we want to immediately run the function and get the task markup returned from renderTasks.

Often when binding functions to “this” in render, you are worried about your function being run at a later time (like in an ‘onClick’), so you need to ensure that the function is run in the component’s context, otherwise ‘this’ will point to the global object or something else.


#3

thank you very much!