I want to create a method in a parent class that will return the location of each subclass that extends it.
// Class A dir is '/classes/a/
class A{
getPath(){
console.log(__dirname);
return (__dirname);
}
}
// Class B dir is '/classes/b'
class B extends A{
}
new A().getPath(); // Prints '/classes/a'
new B().getPath(); // Prints '/classes/a' (I want here '/classes/b');
I understand why class B prints the location of A, but I'm looking for an option of making a method on the parent class that will print the subclass's location. I don't want to override the method in every subclass because it missing the point
I tried process.pwd()
as well.