过去几天来,我一直在努力解决这个可变范围问题,我希望对此有更多的关注。
if(user.password) {
bcrypt.genSalt(10).then((salt) => {
console.log(user);
let hash = bcrypt.hashSync(user.password, salt);
console.log(hash);
user.password = hash;
})
}
console.log(user);
控制台的预期输出如下:
{firstName: "Jon", lastName: "Snow", password: "winter is coming"}
w028238r2u3r928ur0823qp28r3u2
{firstName: "Jon", lastName: "Snow", password: "w028238r2u3r928ur0823qp28r3u2"}
...但是我得到了...
{firstName: "Jon", lastName: "Snow", password: "winter is coming"}
w028238r2u3r928ur0823qp28r3u2
{firstName: "Jon", lastName: "Snow", password: "winter is coming"}