I have a super class called API in a separate file called API.js
class API {
???
}
I also have a bunch of subclasses each in a separate file (MySubClassXXX.js) that include a number of static methods like:
class MySubClass1 {
static method1 () {
return { something }
}
static method2 () {
return { something else }
}
}
I would like yo use these methods in my project like this API.MySubClass1.method1()
how should I import and define the subclasses MySubClass1 in the main class API
You can assign a subclass definition to a property of the base class. class declarations in Javascript are first-class values.
class API {}
API.MySubClass1 = class {
static method1() {
return 'something'
}
}
console.log(API.MySubClass1.method1())
If you only intend to use classes as namespaces here, you can also safely drop class and static keywords with the same effect.