我试图以声明的方式定义派生类的一些字段,就像这样(考虑这是最小的代码示例):
+-------- +------------+-------+--------------+
| blog_id | sub_cat_id | title | created_date |
+-------- +------------+-------+--------------+
| 1 | 1 | ABC | 2018-05-25 |
| 2 | 1 | ABC | 2018-05-22 |
| 3 | 2 | ABC | 2018-05-23 |
| 4 | 2 | ABC | 2018-05-21 |
| 5 | 2 | ABC | 2018-05-20 |
| 6 | 8 | ABC | 2018-05-15 |
+-------- +------------+-------+--------------+
问题是当我尝试从构造函数访问它时,abstract class Car {
model: string;
constructor() {
// some initializing
console.log(`Car model: ${this.model}`);
}
}
class Dodge extends Car {
model = 'Dodge';
constructor() {
super();
}
}
const dodge = new Dodge();
似乎尚未初始化,所以我得到:
model
如何以正确的方式做到这一点?