Typescript-如何访问基类属性
我知道这门课还有其他一些问题,但我的问题和他们不一样:我检查了我的课堂,我已经用了和他们一样的方法。 我将a类扩展为B类,无法访问B中的公共属性。以下是我的(简化)代码:Typescript-如何访问基类属性,typescript,extends,Typescript,Extends,我知道这门课还有其他一些问题,但我的问题和他们不一样:我检查了我的课堂,我已经用了和他们一样的方法。 我将a类扩展为B类,无法访问B中的公共属性。以下是我的(简化)代码: 您不能从静态方法访问此。删除静态,它应该可以工作。您不能从静态方法访问此。删除static,它应该可以工作。您需要读取static和instance之间的差异。您需要读取static和instance之间的差异。 export class A { propertyA: string; constructor
您不能从静态方法访问此。删除
静态
,它应该可以工作。您不能从静态方法访问此
。删除static
,它应该可以工作。您需要读取static和instance之间的差异。您需要读取static和instance之间的差异。
export class A {
propertyA: string;
constructor() {
this.propertyA = "some text";
}
}
import {A} from "./A";
export class B extends A {
constructor() {
super();
}
static method() {
console.log(this.propertyA);
}
}