別のjsファイルで呼び出される別の静的関数を含むファイル内のクラスを持っています。同じファイル内の別のヘルパー関数のクラスの静的関数を呼び出す
module.export = class myClass{
static create(){
...
}
}
// helpers
function callCreate(){
..
}
私はcallCreate
ヘルパー関数でmyClass
の静的関数を呼び出したいです。これどうやってするの?
class MyClass {
property() {
console.log('i am normal member');
}
static func() {
console.log('i am static member');
}
static funcThis() {
console.log('i am static member');
console.log(this === MyClass); // true
this.func(); // will run fine as a static member of a class
this.property(); // will give error as a normal member of a class
}
}
(new MyClass()).property();
MyClass.func();
MyClass.funcThis();
静的メンバーを直接、クラス名によってアクセスされたオブジェクトにリンクされない:クラスの
クラスの静的メンバーは、 'Class.staticVar'のようにアクセスされます。あなたの場合、それは 'myClass.create'になります。 – RaghavGarg