变量:采用Camel 命名法
let userName = "Tom"
常量:采用全大写的命名,且单词以_分割
const USER_INFO = "66"
函数:采用 Camel 命名法
function getUserInfo() {}
类和构造函数:Pascal 命名法,首字母大写
公共属性和方法: 跟变量和函数命名一样。
私有属性和方法:前缀为下划线_, 后面跟公共属性和方法一样的命名方式。
class Polygon {
constructor(height) {
this.area = height * this._width;
}
_width = 20
}
console.log(new Polygon(4).area);
网友评论