【发布时间】:2020-07-30 15:34:17
【问题描述】:
谁能解释一下为什么我在使用这种语法时会收到错误TypeError: Cannot read property 'handleChange' of undefined
const todoItems = this.state.todos.map(function(item) {
return (
<TodoItem
key={item.id}
item={item}
handleChange={this.handleChange}
/>
);
})
但是当我使用如下所示的箭头指针语法时没有错误
const todoItems = this.state.todos.map(
item => <TodoItem key={item.id} item={item} handleChange={this.handleChange}/>
)
注意:在这两种情况下,我都在constructor() 中使用了this.handleChange = this.handleChange.bind(this)。
【问题讨论】:
标签: javascript reactjs ecmascript-6