[转]TypeScript编写类继承函数相关的代码
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)