zoukankan      html  css  js  c++  java
  • 写 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++;
      }
      
  • 相关阅读:
    插入排序实现
    冒泡排序的实现
    选择排序的实现方法
    实现文字的竖排
    一个实体类的定义
    将字符串中的非字母数字,转化为ascii码输出
    根据员工入职时间和合同期计算下一次合同签订时间
    centos安装java的问题解决
    弓箭射小人
    Nature & Science 20102011年全部期刊下载链接
  • 原文地址:https://www.cnblogs.com/ssaylo/p/13520295.html
Copyright © 2011-2022 走看看