In Javascript, is it considered bad practice to give a static method and an instance method the same name?
Suppose I have a class that represents a database table (Model) and I wanted to provide 2 options for fetching some value: (1) with an id, (2) through an instance:
class Foo extends Model {
static getById(id) {
return Foo.query().findById(id);
}
static getBars(id, limit, offset) {
return Foo.getById(id).then(foo => foo.getBars(limit, offset));
}
getBars(limit, offset) {
return this.$relatedQuery('bars').range(limit, offset);
}
}
This example uses Objection JS.
So if you already have an instance of Foo called foo, you can just call foo.getBars(10, 0), rather than Foo.getBars(fooId, 10, 0).