我在一个模块中创建了一个方法:
export function myMethod() {}
在另一个模块中实例化一个类:
注意:此处指在另一个模块中创建类的实例。
import {myMethod} from './methodFile';
class MyClass {
constructor() {}
myMethod // doesn't work
}
是否可以将myMethod
作为MyClass
类的一部分使用?
我正在尝试创建以下代码的等效物:
class MyClass {
constructor() {}
myMethod() {}
}
methodFile
中只有这个东西,我建议使用default
导出。 - Bergi