不能在 React Native 中传递方法的争论中使用它

Cannot use this in the arguement passing in a method in React Native

我正在使用以下格式将参数传递给 redux thunk 函数:

handleComment(dishId){
        console.log(this.state);
        this.props.dispatch(postComment({dishId,this.state.author,this.state.comment,new Date().toISOString()}))
    }

但是它说的是意外的关键字this。但是,console.log 语句 运行 没问题。为什么会出现这个错误?有人可以指导我吗?

意外的关键字通常意味着您写的实际上不是 javascript。

// This is not an object, objects have keys and values
{
  dishId,
  this.state.author,
  this.state.comment,
  new Date().toISOString()
}

// This is an object
{
  dishId,
  author: this.state.author,
  comment: this.state.comment,
  date: new Date().toISOString()
}