Let's say I have these two subclasses:
Male.js
var Person = require('./Person.js');
class Male extends Person {
...
}
module.exports = Male;
Female.js
var Person = require('./Person.js');
class Female extends Person {
...
}
module.exports = Female;
And finally I have this base class:
Person.js
class Person {
static makePersonBySettings(settings) {
var person;
if(settings.gender == 'male') {
person = new Male(settings.name);
}
else if(settings.gender == 'female') {
person = new Female(settings.name);
}
return person;
}
}
module.exports = Person;
Parent's static method depends on knowing what the Male and Female classes are. I can't do require('./Male.js'); at the top of Person.js because Male depends on Person.
Objective-C, Java, and more allow you to do this as the issue is resolved by the compiler.
What's the best way to resolve this issue with Node JS?