-
카테고리
-
세부 분야
풀스택
-
해결 여부
해결됨
userSchema.pre 안에 function 을 화살표 함수로 바꿀 수 없나요?
21.05.12 13:00 작성 조회수 117
0
userSchema.pre('save', function (next) {
// 비밀번호 암호와
var user = this;
if (user.isModified('password')) {
bcrypt.genSalt(saltRounds, function (err, salt) {
if (err) return next(err);
bcrypt.hash(user.password, salt, function (err, hash) {
if (err) return next(err);
user.password = hash;
next();
});
});
} else {
next();
}
});
이거를 function 들을 화살표 함수로 바꿔보았는데 에러가 뜹니다. 혹시 왜그런지 알 수 있을까요?
답변을 작성해보세요.
0
devjeenie
2022.02.12
변수 user에 userSchema를 this로 담았는데
arrow function은 this바인딩을 하지 않아서 this가 userSchema가 아닌 다른게 들어간 듯 합니다
답변 1