강의

멘토링

커뮤니티

Inflearn Community Q&A

banguldev's profile image
banguldev

asked

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

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

userSchema.pre 안에 function 을 화살표 함수로 바꿀 수 없나요?

Resolved

Written on

·

283

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 들을 화살표 함수로 바꿔보았는데 에러가 뜹니다. 혹시 왜그런지 알 수 있을까요?

화살표함수nodejsarrowfunctionreactfunctionfunctiontoarrow

Answer 1

0

변수 user에 userSchema를 this로 담았는데

arrow function은 this바인딩을 하지 않아서 this가 userSchema가 아닌 다른게 들어간 듯 합니다

banguldev's profile image
banguldev

asked

Ask a question