Proxy
を使用しようとしていますが、問題が発生しています。私はそうのようなクラスを持っている:拡張クラスでプロキシがメソッドを取得できない
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()
}
}
私はそのようにようModel
を拡張:
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'はキーワードです。これが問題に関連するかどうかは分かりませんが、私はあなたの変数 'class'を絶対に呼び出さないでしょう。 – Jacob
私は実際に 'class'を使用していません、それは単なる例でした。私はそれを改名した。 –
'model'または' modelBase'に '_items'プロパティがありますか?もしそうなら、項目には 'doSomething'メソッドがありますか? –