相关疑难解决方法(0)

简写"index> = 0 && count ++"做什么?

当我发现这个奇怪的简写时,我正在浪费时间阅读underscore.string函数:

function count (str, substr) {
  var count = 0, index;
  for (var i = 0; i < str.length;) {
    index = str.indexOf(substr, i);
    index >= 0 && count++; //what is this line doing?
    i = i + (index >= 0 ? index : 0) + substr.length;
  }
  return count;
}
Run Code Online (Sandbox Code Playgroud)

合法:在使用上述函数之前请三思而后,不要使用underscore.string


我把这条线放在这里,所以你不要浪费时间找到它:

index >= 0 && count++;
Run Code Online (Sandbox Code Playgroud)

我从未见过类似的东西.我无知在做什么.

javascript shorthand

2
推荐指数
2
解决办法
762
查看次数

标签 统计

javascript ×1

shorthand ×1