- 传递附加参数
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
}
2、
this.x = 9; // this refers to global "window" object here in the browser
var module = {
x: 81,
getX: function() { return this.x; }
};
module.getX(); // 81
var retrieveX = module.getX;
retrieveX();
// returns 9 - The function gets invoked at the global scope
// Create a new function with 'this' bound to module
// New programmers might confuse the
// global var x with module's property x
var boundGetX = retrieveX.bind(module);
boundGetX(); // 81
参考
ReactJS 已经不自动Bind了,要手工绑定