调用函数的方式不同吗?

时间:2019-12-06 10:42:43

标签: javascript reactjs react-native

我在班级中有一个特定于应用程序的Arrow函数,我想在按下Button后调用此函数 所以有两种我不了解它们之间差异的方法

代码

selectPhotoTapped = () => {
    ImagePicker.showImagePicker(options, response => {
      console.log('Response = ', response);

      if (response.didCancel) {
        console.log('User cancelled photo picker');
      } else {
        let source = {uri: response.uri};
        this.setState({
          avatarSource: source,
        });
      }
    });
  };

// First One 
 <TouchableOpacity onPress={this.selectPhotoTapped}>
      <Text>Upload</Text>
 </TouchableOpacity>


// Second One 

 <TouchableOpacity onPress={ () => this.selectPhotoTapped()}>
      <Text>Upload</Text>
 </TouchableOpacity>

0 个答案:

没有答案