• 写 JavaScript 到底写不写分号呢???


    其实我是不喜欢写分号的,好不容易能不写分号,像 python 一样,多爽。

    几年前,各种各样的书大致上都推荐你加分号。

    几年前,曾经由于构建工具有一些问题,导致不加分号可能会出问题。

    jquery依然留着分号,vue源码不用分号, react源码规范需要分号。

    不过,最关键的,还是看团队的代码风格。

    winter推荐写,但是尤雨溪曾经在知乎说

    真正会导致上下行解析出问题的 token 有 5 个:括号,方括号,正则开头的斜杠,加号,减号。我还从没见过实际代码中用正则、加号、减号作为行首的情况,所以总结下来就是一句话:一行开头是括号或者方括号的时候加上分号就可以了,其他时候全部不需要。
    哦当然再加个反引号。

    可是写分号已经习惯了,又何必花力气改习惯去掉它。不加只要不写出bug,也很好。
    反正分号有和没有,对eslint fix来说,只是瞬间的事。。。

    不过在这里,总结一下 no LineTerminator here 的语句。

    1. continue

      outer:for(var j = 0; j < 10; j++)
          for(var i = 0; i < j; i++)
              continue /*no LineTerminator here*/ outter
      
    2. break

      outer:for(var j = 0; j < 10; j++)
          for(var i = 0; i < j; i++)
              break /*no LineTerminator here*/ outter
      
    3. return

      function f(){
          return /*no LineTerminator here*/1;
      }
      
    4. ++ --

      i/*no LineTerminator here*/++
      i/*no LineTerminator here*/--
      
    5. throw | exception

      throw/*no LineTerminator here*/new Exception("error")
      
    6. async

      const f = x/*no LineTerminator here*/=> x*x
      
    7. 箭头函数箭头后面

      const f = x/*no LineTerminator here*/=> x*x
      
    8. yield

      function *g(){
          var i = 0;
          while(true)
              yield/*no LineTerminator here*/i++;
      }
      
  • 相关阅读:
    [apue] FIFO:不是文件的文件
    [apue] 等待子进程的那些事儿
    [apue] popen/pclose 疑点解惑
    [apue] 使用 popen/pclose 的一点疑问
    [apue] 使用 poll 检测管道断开
    [apue] dup2的正确打开方式
    [apue] 管道原子写入量的一个疑问
    [apue] 测试管道容量的一些疑问
    【新阁教育】再也不用担心我的PLC通信不上了
    【新阁教育】三菱PLC的这个功能,真的很强大
  • 原文地址:https://www.cnblogs.com/ssaylo/p/13520295.html
Copyright © 2020-2023  润新知