一种写 JavaScript 更合理的代码风格。
命名规范
-
避免单字母的名字。用你的命名来描述功能。 eslint:
id-length
// bad function q() { // ... } // good function query() { // ... }
-
在命名对象、函数和实例时使用驼峰命名法(camelCase)。 eslint:
camelcase
// bad const OBJEcttsssss = {} const this_is_my_object = {} function c() {} // good const thisIsMyObject = {} function thisIsMyFunction() {}
-
缩略词和缩写都必须是全部大写或者全部小写。
为什么?因为名字是为了可读性,不是为了满足计算机算法。
// bad import SmsContainer from './containers/SmsContainer' // bad const HttpRequests = [ // ... ] // good import SMSContainer from './containers/SMSContainer' // good const HTTPRequests = [ // ... ] // also good const httpRequests = [ // ... ] // best import TextMessageContainer from './containers/TextMessageContainer' // best const requests = [ // ... ]
大约 14 分钟