PracticeEveryday
Class Arrow Function 본문
- 아무리 찾아도 회원 가입 프로퍼티가 찾아지지 않았다 ....
// 위
public async register (email: string, password: string, name: string) {
const newUser = await this.userRepository.save({ email, password, name });
return newUser;
};
// 아래
public register = async (email: string, password: string, name: string) => {
const newUser = await this.userRepository.save({ email, password, name });
return newUser;
};
- arrow function은 this가 없어 execution context chaining을 통해 this를 찾는다 class 내에서 불러 사용하기 위해선
꼭 arrow function을 사용하자 ㅠㅠ
- function을 사용하면 this는 전역으로 binding된다..
'정리 > 에러' 카테고리의 다른 글
swagger param Error (0) | 2022.08.26 |
---|---|
TypeORM find vs findOne (0) | 2022.08.18 |
Docker Error (0) | 2022.08.16 |
Comments