나는 타이프 라이터로 일하고 있어요 그리고 난 클래스타이프 라이터, 정적 메소드 상속
사이의 정적 상속에 문제가 는는 사람이 나에게 다음의 결과를 설명 할 수 :
class Foo {
protected static bar: string[] = [];
public static addBar(bar: string) {
this.bar.push(bar);
}
public static logBar() {
console.log(this.bar);
}
}
class Son extends Foo {
protected static bar: string[] = [];
}
class Daughter extends Foo {}
Foo.addBar('Hello');
Son.addBar('World');
Daughter.addBar('Both ?');
Foo.logBar();
Son.logBar();
Daughter.logBar();
현재 결과 :
를[ 'Hello', 'Both ?' ]
[ 'World' ]
[ 'Hello', 'Both ?' ]
하지만 내가 원하는 :
[ 'Hello' ]
[ 'World' ]
[ 'Both ?' ]
,
고정 bar
속성을 다시 선언하지 않고 해결책이 있습니까?
감사합니다.
이 * 정적 * –