在ArkTS中,静态变量和方法是属于类自身的,无法通过this访问,因为this是指向类的实例化对象。如果要在类中访问静态变量和静态方法,需要使用类名访问。
// 访问静态变量或者执行静态方法
class TestStatic {
static aaa: string = '3333';
static getAAA () {
// console.log(this.aaa) 不能通过this访问静态变量,且静态变量只能在静态方法中使用
return TestStatic.aaa;
}
}
TestStatic.aaa;