【发布时间】:2020-06-23 03:45:26
【问题描述】:
class Message {
constructor(text) {
this.text = text;
}
toString() {
return this.text;
}
}
class ErrorMessage extends Message {
constructor(text, code) {
super(text);
this.code = code;
}
}
const message = new ErrorMessage('Test', 404);
原型到底是什么,假设我们调用:ErrorMessage.prototype 还是 Message.prototype? 哪些属性存储在哪些对象(文本、toString 和代码)中?
【问题讨论】:
标签: javascript inheritance prototype chain