变量的名字又叫做标识符,需要遵守一定的规则
JavaScript 标识符必须以
- 字母
- 下划线_
- 美元符号 $开头
变量命名风格
- lowerCamelCase:首字母使用小写,小驼峰
- UpperCamelCase:首字母大写,大驼峰
- 用 _开头或结尾的变量用于私有变量
- 一个前导下划线:表示非公有
- 一个后缀下划线:避免关键字冲突
- 两个前导下划线:当命名一个类属性引起名称冲突时使用
- 两个前导和后缀下划线:有特殊用途的对象或者属性,例如 init和 str
- 使用 class时用到的首字母是大写的,在编码中应尽量避免 定义 class
- 不要使用保留字作为变量名,名字不能包含空格
- javascript 对象名不需害怕过长,应明确定义每个变量意义
变量应用场景
is_superuser:『是否超级用户』,只会有两种值:是/不是
has_error:『有没有错误』,只会有两种值:有/没有
flag_found:『标志位变量』,只会有两种值:找到/没找到
allow_vip:『是否允许 VIP』,只会有两种值:允许/不允许
debug:『是否开启调试模式』,被当做 bool 主要是因为约定俗成
全局变量
全局变量,全部大写,多个单词用下划线隔开,
如需要阻止导入模块内的全局变量,可以加一个前导下划线,GLOBAL_VAR_NAME,GLOBAL_VAL
根目录文件
.babelrc
.editorconfig
.jshintrc
.github
.gitignore
node_modules
jsconfig.json
package.json
package-lock.json
webpack.config.js
gulpfile.babel.js
README.md
前端项目命名
router 路由
routes & views
server 服务端代码
config 配置文件
mvc
models
controllers
views
middlewares 中间件
legacy 兼容历史版本或兼容旧浏览器的代码
设计模式
adapters 适配器
components 组件
templates template 模板
plugins 插件
fixtures
app
build scripts 构建脚本
core 核心文件
测试命名
test tests tests 测试
unit, spec 单元测试,一般在 test目录下
e2e 端对端测试,一般在test目录下
benchmarks
src source 源代码
lib
docs 文档
libs 库文件 library的缩写
vendor 第三方库
tasks 任务
dist
assets 资源,一般用来放图片或 css文件
css styles
sass less
font fonts icon icons
js javascript typescript
img images
static 静态资源
examples example demo 示例
utils tools helpers 工具代码
bin 命令脚本
常用的英文单词
util
data
api
pages html 页面
common public 公共文件
resources
packages 很多项目会打包出多个npm包,用来减小体积,一般会用packages来放不同的包
client
browser
snapshots
main
themes
support
integration
actions
doc
types
ui
shared
basic
bootstrap
node
layout
mixins
cli
in
services
events
layouts
media
jquery
misc 杂项,miscellaneous的缩写
ee
demos
stylesheets
en
.circleci
files
partials
settings
scss
screenshots
base
theme
default
middleware
locales
com
res
json
store
svg
android
commands
react
java
mocks
specs
reducers
content
containers
editor
_layouts
plugin
constants
website
wrapper
ios
style
extensions
list
debug
routes
home
webpack
tabs
gradle
input
component
search
site
http
button
model
form
values
table
benchmark
features
es
npm
auth
view
module
qunit
markdown
hooks
javascripts
functions
flow-typed
image
AppIcon.appiconset
fr
errors
prettify
event
nested
.vscode
admin
directives
toolbar
dom
elements
web
Base.lproj
Images.xcassets
xcschemes
project
error
storage
xcshareddata
samples
logo
menu
requirejs
async
custom
guides
dev
slider
text
_includes
loader
filters
script
help
flow
generators
tooltip
global
ja
dialog
foo
mipmap-hdpi
logs
system
mipmap-mdpi
mipmap-xhdpi
mipmap-xxhdpi
internal
simple
windows
advanced
performance
user
parser
redux
functional
blog
keystores
options
gulp
methods
chrome
mocks
modal
apps
perf
release
dashboard
file
network
classes
bench
tags
lang
cache
users
meta
ru
includes
link
angular
xml
audio
python
php
init
typings
login
navigation
empty
collections
grid
jest
widgets
logos
renderer
testing
math
autocomplete
package
helper
external
render
rules
notifications
mode
handlers
subdir
service
date
grunt
path
forms
selection
code
animation
header
general
bar
array
cs
renderers
filter
locale
configs
local
include
pl
effects
playground
ko
schema
mobile
select
it
output
color
index
string
ext
browserify
migrations
db
display
stores
request
shell
docker
log
edit
other
selectors
expected
cases
info
controls
console
go
controller
sub
exports
ajax
compiler
express
sounds
import
highlight
design
_locales
providers
snippets
generator
conf
about
platform
sidebar
dropdown
www
reference
coffeescript
babel
page
loaders
extras
install
buttons
properties
Modules
timeline
function
github
ace
security
dir
defaults
App
canvas
shapes
id
_data
query
diff
runtime
mocha
uk
globals
url
panel
widget
video
groovy
ruby
codemirror
colors
objects
favicon
reporters
container
handlebars
stylus
charts
session
utilities
vue
map
graph
yaml
languages
recipes
items
navbar
profile
object
preview
translations
amd
number
tutorials
workers
Button
nginx
syntax
accordion
dir
fs
private
mock
dialogs
definitions
deps
imports
meteor
messages
builder
transforms
attributes
card
setup
hello-world
ast
touch
bower_components
require
progress
manual
comment
language
documentation
sandbox
extension
lua
promise
rust
q
keys
datepicker
queue
polyfills
tutorial
linux
modals
sql
es
skins
nl
chat
dir
stream
chart
electron
jsx
Home
preferences
sk
standalone
proxy
tree
zh-cn
root
el
tmp
perl
window
coffee
nodes
getting-started
create
contents
View
en-US
out
calendar
.storybook
commonjs
basics
share
state
websocket
dependencies
modifiers
upgrade
guide
menus
schemas
sample
comments
win
old
new
lodash
etc
extend
tables
ms
favicons
font-awesome
glob
flash