boiler-plate's People
boiler-plate's Issues
mongoose에서 arrow function을 사용할 때 /api/users/register post 요청이 실패하는 이유
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();
}
});
자바스크립트 코드에서 arrow function은 function 표현식과 다르게 this를 바인딩하지 않는다. 다시 말해서 화살표 함수는 자신의 this를 가지고 있지 않다. (= 바인드 하지 않는다.)
그리고 화살표 함수는 항상 익명이며, 이 함수 표현은 메소드 함수가 아닌 곳에 가장 적합하다.
위의 코드를 화살표 함수로 작성했다가 function 표현식으로 바꿔주니 post 요청이 성공했다.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.