我尝试在ES6中编写ActiveRecord类。但是我对静态函数的继承有问题。
class ActiveRecord {
static tableName() {
this.name
}
static findById(id) {
// read from database balabala, need tableName
console.log(this.tableName())
}
}
class Contact extends ActiveRecord {
constructor() {
super()
}
static tableName() {
return 'contact'
}
}
Contact.findById(1) // got "ActiveRecord", I need it to be "contact" but it didn't work that way
我认为我重写了静态tableName函数,但findById没有调用Contact的tableName函数。我的问题是如何调用ContactName的tableName而不是ActiveRecord的tableName?