class修饰符
readonly 只读
private 只能类的内部使用
protected 只能类的内部和继承的子类使用
public不限制
class的super
prototype.constructor.call
class Doms {
name:string
constructor(name:string) {
this.name = name
}
protected getName():string {
return this.name
}
}
class Vues extends Doms {
constructor(name:string) {
super(name)
}
}
let app1 = new Vues('cqs');
app1.name
class的static
静态方法或属性 只能静态方法之间调用 或者类名调用
class Vues {
static version() {
return '1.0.0'
}
static getVersion() {
this.version()
}
}
Vues.version()
interface 定义类
使用关键字 implements 后面跟interface的名字多个用逗号隔开
interface VueCLs {
option: string,
init(): void
}
interface Vnode {
tag: string
}
class Vue implements VueCLs,Vnode {
option: string
tag: string
constructor(option: string, tag: string) {
this.option = option;
this.tag = tag;
this.init()
}
init(){
}
}
clas的abstract
抽象类 只能定义不能实现 继承了抽象类就必须实现定义的抽象方法
abstract class A {
name: string
constructor(name: string) {
this.name = name;
}
print(): string {
return this.name
}
abstract getName(): string
}
class B extends A {
constructor() {
super('cqs')
}
getName(): string {
return this.name
}
}
let b1 = new B();
b1.print()
console.log(b1.getName());