命名规范

2019-04-04  本文已影响0人  琢磨先生lf

from https://github.com/AlloyTeam/CodeGuide

项目命名

目录命名

JS 文件命名

示例:account-model.ts
示例:scan-file.component.ts

CSS, SCSS 文件命名

HTML 文件命名

JS 命名规范

angular 项目命名规范

文件命名规范

命名规范

变量

// 好的命名方式
let maxCount = 10;
let tableTitle = 'tableTitle';

// 不好的命名方式
let setConut = 10;
let getTitle = 'getTitle';

常量

const MAX_COUNT = 10;
const URL = '//www.huifenqi.com';

函数 & 方法

// 是否可阅读
function canRead() {}
// 获取名称
function getName() {}
// 事件回调
function onSelectChange() {}

类 & 接口

class Persion {
  constructor(name) {
   ...
  }
}

let person = new Person('TOM');

类的成员

class Person {
  // 私有属性 
  private name: string;
  private _hobby: string;
  constructor() { }

  set hobby(hobby) {
    this._hobby = hobby;
    this.doSomething();
  }
  // 公共方法
  getName() {
    return this._name;
  }
  // 公共方法
  setName(name) {
    this._name = name;
  }
}

示例

前缀 含义 类型
can 判断是否可执行某个动作 方法
get 获取某个值 方法
set 设置某个值 方法
load 加载某些数据 方法
has 判断是否含义某个值 boolean型变量
is 判断是否为某个值 boolean型变量
nsOn Output输出属性 EventEmitter

上一篇下一篇

猜你喜欢

热点阅读