TypeScript编写类,继承、函数相关的代码
class Person { private name:string private age:Number constructor(name:string, age:Number) { this.name = name; this.age = age } public getPersonInfo():string{ return `My name is ${this.name} ange age is ${this.age}`; } } class Employee extends Person { private department:string constructor(name:string, age:number, department:string) { super(name, age) this.department = department } public getEmployeeInfo():string {{ return this.getPersonInfo() + ` and work in ${this.department}` }} } let person2 = new Employee("baoshan", 33, "Huawei") console.log(person2.getPersonInfo()) console.log(person2.getEmployeeInfo())
参考官方文档:<HarmonyOS第一课>ArkTS开发语言介绍-华为开发者学堂 (huawei.com)
标签:TypeScript,name,代码,private,department,编写,age,string From: https://www.cnblogs.com/zhzhang/p/17928229.html