ARKTS: 鸿蒙编程-定义类

如果ARKTS编程语言对 类中定义的对象 不赋初始值就必须写
constructor ,否则,不用写constructor .

例如:
export class fooClass{
id: number;
name: string;
constructor (id:number, name:string){
this.id = id,
this.name = name
}
}
不用写constructor 的例子:
export class fooClass{
id: number = 0;
name: string = '';
}

posted @ 2026-01-21 08:02  samrv  阅读(2)  评论(0)    收藏  举报