webstorm里面关于return返回空值的警告的一个解释
Unnecessary return statements are those which return no value and occur just before the function would have "fallen through" to the bottom.
这是对第二个return的warn,不能这样用呢,程序如下:
exports.consumeAmountGetReward = function (user,callback) {
var activity = QActivity.getValidActivity('consumeAmount'),
config = QSetting.current(),
localize = config.localize;
if(!activity){
callback(localize['20088']);
return;
}
if(user.consumeAmountRemainCount <= 0){
callback(localize['20076']);
return;
}else{
user.consumeAmountRemainCount -= 1;
user.consumeAmountCrystal -= activity.data.crystal;
businese.UserManager.saveUser(user, function (err) {
if(err){
callback(err);
}else{
callback(null,outputConsumeAmountActivity(user,activity));
}
});
}
};
3 回复
因为你的那个被警告的 return 即使不加,后面也不会执行了。webstorm 很智能,就告诉你这个 return 不必要。
你把那个 return 下面的 else block 给去掉的话,提示也就消失了。
ok,3!
3Q