美文网首页
TypeScript定义类

TypeScript定义类

作者: 践道修行者 | 来源:发表于2020-08-06 11:00 被阅读0次

    通过构造函数定义类

    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