return res.redirect('/')这个return有啥用?
return res.redirect('/');里面这个return有什么用啊,我把return删除了,效果是一样的,它有啥用呢?????
return res.redirect('/');里面这个return有什么用啊,我把return删除了,效果是一样的,它有啥用呢?????
2017-03-22
有用啊,可以阻止程序继续往下走
User.findOne({name: name},function(err, user){
if(err) console.log(err);
console.log(user)
if(!user) return res.redirect('/');
user.comparePassword(password, function(err, isMatch){
if(err) console.log(err);
if(isMatch) {
console.log('Password is matched');
return res.redirect('/');
}else{
console.log('Password is not matched');
}
})
})如果没有return不管有没有user都会比较密码值,多浪费性能
举报