1

编辑: Syntastic 配置为使用 JSLint

EDIT2:我使用的是 JavascriptLint,而不是 JSLint

在下面的代码合成警告function inside does not always return a value

function(){
 switch(age){
 case 1:
  return 'won';
 case 2:
  return 'too';
 case 3:
  return 'tree';
 default:
  throw 'wow man, you are old!';
  break; //technically redundant
 }
}

我意识到default不返回值,而是throw结束执行。这是一个 Syntastic 错误,还是我应该改变我的编码风格?我应该return在之后发表声明throw吗?

4

1 回答 1

2

Syntactic 在底层使用JSLint来检查 Javascript 语法。

众所周知,JSLint 为了避免错误而过于谨慎。您可以忽略该消息以更好地判断,或关闭此特定警告,或在return此处添加冗余。

我个人更喜欢满足 JSLint 的要求而不是关闭警告。只需确保在//Satisfying JSlint附近添加评论,return以便其他人了解冗余。

于 2011-10-30T23:56:26.527 回答