나는이 질문에 자바 스크립트 및/또는 특히 React-Native보다 ESO6가 더 많이 포함될 수 있다는 의심의 여지가 있지만 시도하겠습니다. 다음과 같은 구성 요소가 있습니다 :react-native - 인자를 함수로 호출하기
export default class Body extends Component {
componentWillMount() {
this.refresh();
}
clickme() {
console.log('I have been pressed!!!!!');
}
refresh() {
this.props.populateGrid();
}
render() {
return (
<View style={styles.body}>
<Grid inGrid={this.props.grid} />
<Button
onPress={this.clickme}
title={'PressMe'}
/>
</View>
);
}
}
먼저 'this.clickme()'를 onPress에 전달했습니다. 그것은 작동하지 않았다. 그것은 작업을 시작한 중괄호를 제거한 후에였습니다. 왜? 우리는 보통()을 포함한 함수를 호출하지 않습니까? 또한 때로는 다음과 같은 형식으로 전달해야합니다. something = {() => this.clickme()}. 왜/언제?
1. {this.clickme}
2. {this.clickme()}
3. {() => this.clickme()}
감사합니다 : 할 때와 같이
그래서 우리는 함수를 호출합니다.
감사합니다 - 의미가 있습니다. 나는 그것에 대해 더 많이 읽을 것이다. – Wasteland