-
카테고리
-
세부 분야
풀스택
-
해결 여부
미해결
User.js에서 ES6 사용
20.07.14 22:58 작성 조회수 109
0
User.js (유저 모델) 에서는 ES6 문법을 사용하지 않는 이유는 뭔가요? 화살표함수로 작성해봤더니 제대로 동작하지 않네요..
index.js랑 어떻게 다르다고 이해하면 될까요~?
답변을 작성해보세요.
2
John Ahn
지식공유자2020.07.15
https://mongoosejs.com/docs/guide.html
- Do not declare methods using ES6 arrow functions (
=>
). Arrow functions explicitly prevent bindingthis
, 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
답변 3