반응에서 다음과 같은 코드가 있습니다.
export class Foo extends React.Component {
function_name() {
this.setState({blah: 'bleh'})
}
this.function_name()
}
하지만 정말 이렇게 작동하고 싶습니다
function_name() {
this.setState({blah: 'bleh'})
}
export class Foo extends React.Component {
this.function_name()
}
이런 종류의 작업을 수행 할 수있는 방법이 있습니까? 기본적으로 클래스 외부의 함수가 들여 쓰기를 줄이기를 원합니다. 문제는 내가 얻는 것 function_name is not a function
입니다.
클래스를 선언 / 내 보낸 후 프로토 타입에 할당 할 수 있습니다.
export class Foo extends React.Component {
this.function_name()
}
Foo.prototype.function_name = function() {
this.setState({blah: 'bleh'})
};
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다