강의

멘토링

커뮤니티

Inflearn Community Q&A

youmeeeee1159's profile image
youmeeeee1159

asked

Node and React series that you can learn by following - Basic lecture

Node React Basics Lecture #11 Login Function with Bcrypt (1)

User.js에서 ES6 사용

Written on

·

260

0

User.js (유저 모델) 에서는 ES6 문법을 사용하지 않는 이유는 뭔가요? 화살표함수로 작성해봤더니 제대로 동작하지 않네요..

index.js랑 어떻게 다르다고 이해하면 될까요~? 

nodejsreact

Answer 3

2

John Ahn님의 프로필 이미지
John Ahn
Instructor

https://mongoosejs.com/docs/guide.html

  • Do not declare methods using ES6 arrow functions (=>). Arrow functions explicitly prevent binding this, so your method will not have access to the document and the above examples will not work.

몽구스 공식 문서에는 이렇게 나왔는데요 ~ 
화살표함수는 this를 바인딩 하지않아서  User의 다큐멘트를 가질수 없어서 그럽니다 ^^ 
 
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/this
이걸 살펴보면 더 이해가 잘될것 같습니다 ~~! 

0

user.comparePassword is not a function
이 에러가 자꾸 뜨는데 찾질못하겠습니다...
혹시 답변 가능하신가요 ㅠㅠ

모델에서 comparePassword 메소드를 만들지 않은 것 같습니다

0

Youme Choi님의 프로필 이미지
Youme Choi
Questioner

답변 감사합니다!! :)

youmeeeee1159's profile image
youmeeeee1159

asked

Ask a question