Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

命名规范 #10

Open
Qhappyman opened this issue May 5, 2019 · 0 comments
Open

命名规范 #10

Qhappyman opened this issue May 5, 2019 · 0 comments

Comments

@Qhappyman
Copy link
Owner

js命名规范

众所周知,前端开发对于代码可维护性与规范是非常严格的,这就需要我们有一套统一的规范,就像一种协议一样,不管谁看都能认识,下面就来详细解释一下:

项目命名

全部采用小写方式,以下划线分割

my_project_name

就像这样

目录命名

参照项目命名规则;有复数结构时,要采用复数命名法

scripts,styles,images,data_models

js文件命名

常量

采取全大写的命名。且单词以** _ **分割,常量通常用于ajax与url请求,和一些不改变的数据

const MAX_COUNT = 10;

变量

小驼峰式命名法
前缀应当是名词(函数为动词),以此区分函数与变量

let maxCount = 10;

函数

小驼峰式,前缀为动词

function canRead(){
		return true;
}

类,构造函数

大驼峰式,首字母大写,前缀为名称

class Person{
		public:
		....
}
let person = new Person();

类的成员

公有属性和方法:和变量与函数命名一样
私有属性和方法:前缀为下划线,后面和私有属性一样

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant