简体   繁体   English

Airbnb JavaScript指南中的开关示例用法是否不一致?

[英]Is the switch example usage in airbnb javascript guide inconsistent?

I'm catching up on javascript that I have not used since some time, doing so by inspiring most of my coding style from the Modern Javascript coding guide by AirBnb 我从AirBnb的Modern Javascript 编码指南中激发了我的大部分编码风格,从而赶上了一段时间以来从未使用过的javascript。

In the paragraph regarding switch I think there is an inconsistency. 有关switch段落中,我认为存在不一致之处。 But that's not as if the Airbnb guide had been read by tons of guy before me... 但这并不是好像Airbnb指南被我之前的很多人读过了...

Check the line for case 4 which alone does not use curly braces, but rather no braces at all like in the style before which is considered bad. 检查第case 4case 4的行,它单独不使用花括号,而是根本没有花括号,就像之前的样式一样。 However the default case comes back at using curly braces. 但是, default情况是使用花括号恢复。

switch (foo) {
  case 1: {
    let x = 1;
    break;
  }
  case 2: {
    const y = 2;
    break;
  }
  case 3: {
    function f() {
      // ...
    }
    break;
  }
  case 4:
    bar();
    break;
  default: {
    class C {}
  }
}

If it is not an inconsistency, then what would be the sound reason for this different case 4 ? 如果不是不一致,那么这种不同case 4的合理原因是什么?

There is no inconsistency. 没有不一致的地方。 The curly braces are used as a scope for the lexical declarations. 大括号用作词法声明的范围。 Case 4 is the only case without any such declaration. 情况4是唯一没有任何此类声明的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM