当前位置:网站首页>JS Standard
JS Standard
2022-06-10 18:51:00 【SeriousLose】
Use spaces , Instead of using tab
- Except for the line terminator , In the system file , Spaces are the only characters that represent white space , It means tab Cannot be used as an indent . Regulations with 2 A space ( instead of 4 individual ) To indicate indentation .
An indispensable semicolon
- Every statement must end with a semicolon , Don't rely on the compiler to automatically insert semicolons .
Don't use var
- Declare local variables with const perhaps let, By default const, Unless the variable needs to be reassigned .
The arrow function perfectly replaces function
- Arrow functions are not only syntactically simple and easy to read , And fixed this The problem of , Especially in nested functions .
Replace string splicing with template string
- Use template string ( use ` Division ) Handle complex strings , Especially when dealing with multi line strings .
Don't wrap long strings with backslashes
- although ES5 That's allowed , But it will lead to strange mistakes , And it will mislead people who read the code
for Cycle preference “for… of”
- stay ES6 in , Support for multiple for Cyclic writing , Maybe you've used it all , But try to choose for… of Well .
Do not use eval()
- Do not use eval() ( Except code loaders ), It will bring about potential uncertainty , Because in CSP Does not work in the environment .
Constants are underlined with capital letters
- Constants are represented by uppercase letters and underscores , All words are capitalized , Underline split .
Declare one variable at a time
- Declare one variable at a time , Don't write as let a = 1, b = 2;
single quote , Don't use double quotes
- Ordinary strings are separated by single quotation marks (’), If the string contains single quotes , Then consider using the template string .
name
- css Class name , Use lowercase English + -;
- function , Name the hump ;
notes
- Legal information ( For example, copyright and copyright notices )
- Provide notes for information ( For example, explain the return value of an abstract method , Of course, it is better to reflect in the method name , Thus omitting the notes )
- The interpretation of intention ( Explain your intentions to some code that doesn't seem to conform to common sense , Such as sleep function )
- Caution ( Warn code that will have some consequences after execution )
- TODO notes ( Tell the others that there is still work to be done , And what it should be like when it is finished in the future )
- avoid
- Redundant comments log comments ( Record each modification log , At present, the source code management is very perfect today , Logging comments should be discarded )
- Annotated code ( Don't comment out the code directly ! Delete if useless , Comments rather than deletions can lead others to think that this code is still useful )
- Ownership and signature ( Through source code management , Signatures can also be discarded )
- Comments after parentheses ( Do not write comments after parentheses )
- Too much information ( Don't add irrelevant information to your comments )
边栏推荐
猜你喜欢

5. golang generics and reflection

Cross domain error: when allowcredentials is true, allowedorigins cannot contain the special value "*“

VMware ESXi 各版本号对照表

企业管理者的质疑,这么多年的信息化,我们的钱花哪去了?

Enterprise data quality management: how to evaluate data quality?

Real time business intelligence Bi (II): reasonable ETL architecture design to realize quasi real time Business Intelligence BI

How to transform digital transformation? Which way?

muduo源码剖析——以三个切片浅析muduo库代码设计的严谨性、高效性与灵活性

两部门发文明确校外培训机构消防安全条件

Custom types: structural bodies
随机推荐
Some summary about YUV format
数据处理时代,数据分析成为基础建设
In the digital age, why should enterprises make digital transformation?
Db2 SQL PL简介
Huawei cloud hcde Cloud Road phase II: how does Huawei cloud help small and medium-sized manufacturing enterprises' digital transformation?
Request header field xxxx is not allowed by Access-Control-Allow-Headers in preflight response问题
Real time business intelligence Bi (II): reasonable ETL architecture design to realize quasi real time Business Intelligence BI
Anchor type and row data type of DB2 SQL pl
数字化转型怎样转?朝哪转?
LoRa模块无线收发通信技术详解
滑动窗口最值问题
VMware esxi version number comparison table
智慧城市网络安全建设框架及实践
VMware Horizon 8 2111 部署系列(十六)Blast带宽测试
vcsa7u3c安装教程
Three ways generated by stream lambda
Adobe Premiere基础-不透明度(混合模式)(十二)
AD18器件库导入简介
How to set up salesmartly for Google Analytics tracking
JS Standard