Proxy
을 사용하려고하는데 문제가 있습니다. 나는 다음과 같이 Model
을 확장프록시가 확장 클래스에서 메서드를 가져올 수 없습니다.
export class Builder {
public doSomething(...args: (string | number | Raw | Object)[]): this {
// Do stuff
return this
}
}
export class ModelBase extends Builder {
protected _items = {}
}
export class Model extends ModelBase {
public constructor(options?: ModelSettings) {
super(options)
return new Proxy(this, {
get: function (target, property) {
return target._items[property] || target
}
})
}
public static create() {
return new this()
}
}
: 나는 수업과 같이이
export class MyClass extends Model {
public constructor() {
super({/* Some options go here */})
// Do some stuff
}
public static getItems() {
let t = this.create()
t.doSomething()
}
}
가 그럼 난 클래스의 인스턴스를 생성
getItems()
를 호출합니다. 나는이 프로그램을 실행할 때
MyClass.getItems()
, 나는 오류를 얻을 : doSomething()
클래스 ModelBase
내에
TypeError: t.doSomething is not a function
. 내가 Proxy
일을 평소와 같이 처리하는 경우. 그래서 부모 클래스에 액세스 할 수없는 이유를 알고 싶습니다.
'class'는 키워드입니다. 이 문제에 전혀 관련이 있는지 잘 모르겠지만, 나는 확실히 귀하의 변수를'클래스'라고 부르지 않을 것입니다. – Jacob
실제로'class'를 사용하지 않고 있습니다. 단지 예제 일뿐입니다. 나는 그것의 이름을 바꾸었다. –
'model' 또는'modelBase'에'_items' 속성이 있습니까? 그렇다면 _items에는'doSomething' 메소드가 있습니까? –