7. class:
①. 在构造函数和原型链来实现继承的,es6有了class(内部还是原型链实现).
②. 修饰符:public
③. class Animal {
readyonly name: string,
static categorys: string[] = ['a', 'b'];
constructor(name: string) {
this.name = name;
}
}
8. enums:
(1). 内联枚举:
①. 举例:
enum Dir {
Up,
Down,
Left,
Rigth,
}
Dir.Up // 0
Dir[0] // Up
②. 编译后的代码:
(function (Dir) {
Dir[Dir["up"] = 0] = "Up";
Dir[Dir["up"] = 1] = "Down";
Dir[Dir["up"] = 2] = "Left";
Dir[Dir["up"] = 3] = "Right";
})(Dir || (Dir = {}));
③. 代码量有点多.
(2). 常量枚举:
①. 举例:
const enum Dir {
Up = 'UP',
Down = 'DOWN',
Left = 'LEFT',
Rigth = 'RIGTH',
}
const value = 'UP'
if (value === Dir.Up) {
console.log('go');
}
②. 编译后的代码:
var value = 'UP';
if (value === 'UP') {
console.log('go')
}