๋ค์ ์ฝ๋๋ฅผ ์ฌ์ฉํ ๋ :
userSchema.pre('save', (done) => {
if(this.isModified('password')) {
bcrypt.hash(this.password, null, null, (err, hash) => {
if(err) return next(err);
this.password = hash;
this.updated_at = new Date().toISOString();
done();
});
} else {
return done();
}
});
๋ค์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
TypeError: this.isModified is not a function
at model.userSchema.pre (C:\code\project\core\models\user.js:26:11)
at _next (C:\code\project\node_modules\hooks-fixed\hooks.js:62:30)
at fnWrapper (C:\code\project\node_modules\hooks-fixed\hooks.js:186:8)
at model.Object.defineProperty.value.fn (C:\code\project\node_modules\mongoose\lib\schema.js:221:11)
at _next (C:\code\project\node_modules\hooks-fixed\hooks.js:62:30)
at fnWrapper (C:\code\project\node_modules\hooks-fixed\hooks.js:186:8)
at C:\code\project\node_modules\mongoose\lib\schema.js:196:17
at C:\code\project\node_modules\kareem\index.js:127:16
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
๋ฌธ์ :
this
์ ๋ฌธ์, ์ฟผ๋ฆฌ ๋๋ ์คํค๋ง๊ฐ ์๋๋๋ค. ๊ฐ์ {}
์ด๋ป๊ฒ ํด๊ฒฐํ ์ ์์ต๋๊น?
this
์ ๋ฒ์๋ฅผ ๋ณ๊ฒฝํ๋ ์ฝ๋ฐฑ์ ํ์ดํ ์ฐ์ฐ์๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ์ผ๋ฐ ์ฝ๋ฐฑ์ ์ ์ํ๋ฉด ๊ด์ฐฎ์ต๋๋ค. ์:
userSchema.pre('save', function(done) {
});
ํ์ธ. ๊ฐ์ฌ ํด์. ํจ๊ณผ๊ฐ์๋ค.
eslintrc ์์
2016๋
11์ 29์ผ ํ์์ผ ์ค์ 5:16, Nick Rameau ์๋ฆผ @github.com
์ผ๋ค:
ํ์ดํ ๊ธฐ๋ฅ์ผ๋ก ํ ์์๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น? ์ ๋ ES6์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
eslintrc๊ฐ ์ผ๋ฐ ์ฝ๋ฐฑ์ ๋ํด ๋ถํํ๊ณ ์์ต๋๋ค.โ
์ด ์ค๋ ๋์ ๊ฐ์ ํ๊ธฐ ๋๋ฌธ์ ์ด ๋ฉ์์ง๋ฅผ ๋ฐ๊ณ ์์ต๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/Automattic/mongoose/issues/4537#issuecomment-263567210 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ABi5KbZG27HnF2sX2RwDIhTp4Rz1lIG_ks5rDCW1gaJpZM4J_8-c
.
๋๋์ด ๋ฌธ์ ๊ฐ์์์ต๋๋ค. ๋์์ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค @VictorGerritsenQLVR!
function(next)
์ฌ์ฉํ๋ ๋์ ํ์ดํ ์ฐ์ฐ์๋ฅผ ์์ฉํ๋๋ก ์ฝ๋๋ฅผ ๋ณ๊ฒฝํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
@domarp-j ์ข์ ์ง๋ฌธ์ ๋๋ค. ๊ณฐ๊ณฐ์ด ์๊ฐํด ๋ณด๊ณ ์์๋ด๋ ค๊ณ ํ์ง๋ง ๊ทธ๋ฅ ์ผ๋ฐ ์ฝ๋ฐฑ ๊ธฐ๋ฅ์ผ๋ก ๋ฐ๊พธ๋ ๊ฒ๋ณด๋ค ๋ ์ฌ์ด ๋ฐฉ๋ฒ์ด ๋ ์ค๋ฅด์ง ์์์ต๋๋ค. ๋ค๋ฅธ ์ฌ๋์ด ํ์ ์๋ ์์ต๋๋ค. ์ด ๋ฌธ์ ๋ฅผ ๊ณ์ ์ฃผ์ํ๊ฒ ์ต๋๋ค.
๊ทธ๊ฒ์ ํ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ๋ฑ๋ฑํ ํ์ดํ๋ ๋ฌธ๋งฅ์ ๋ํ ์ดํ ๋ฒ์๋ฅผ ์ฌ์ฉํฉ๋๋ค.
๊ฐ์ ๋ฌธ์ ๊ฐ ์์๋๋ฐ ๋์์ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
์๋ ํ์ธ์, es6 ํ์ดํ ๊ธฐ๋ฅ๊ณผ ๋์ผํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋งค์ฐ ๊ฐ์ฌํฉ๋๋ค!
์ข์ ๊ฐ์ฌํฉ๋๋ค
๊ฐ์ฌ ํฉ๋๋ค. ์ ์๊ฒ๋ ํจ๊ณผ์ ์ ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
this
์ ๋ฒ์๋ฅผ ๋ณ๊ฒฝํ๋ ์ฝ๋ฐฑ์ ํ์ดํ ์ฐ์ฐ์๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ์ผ๋ฐ ์ฝ๋ฐฑ์ ์ ์ํ๋ฉด ๊ด์ฐฎ์ต๋๋ค. ์: