GithubHelp home page GithubHelp logo

boiler-plate's People

Contributors

btiac1129 avatar

Watchers

 avatar

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.