通过构造函数定义类
class Car {
engine: string
constructor(engine: string) {
this.engine = engine
}
disp():void {
console.log("发动机为 : "+this.engine)
}
}
let car = new Car("V8")
car.disp()
class Car {
engine: string
constructor(engine: string) {
this.engine = engine
}
disp():void {
console.log("发动机为 : "+this.engine)
}
}
let car = new Car("V8")
car.disp()
本文标题:TypeScript定义类
本文链接:https://www.haomeiwen.com/subject/otforktx.html
网友评论