【发布时间】:2018-07-24 14:12:39
【问题描述】:
我有以下代码,我正在尝试从基类继承。为什么代码说identify() 没有定义?它不应该从基类中调用函数吗?
错误:ReferenceError:标识未定义 source1.js:23:9
class TestBase {
constructor() {
this.type = "TestBase";
}
run() {
console.log("TestBase Run");
}
identify() {
console.log("Identify:" + this.type);
}
}
class DerivedBase extends TestBase {
constructor() {
super();
this.type = "DerivedBase";
}
run() {
console.log("DerivedBase Run");
identify();
}
}
window.onload = function() {
let derived = new DerivedBase();
derived.run();
}
【问题讨论】:
-
你试过打电话给
this.indentify()吗? -
是的,我做到了。没用。
-
@SinisterMJ
this.identify()绝对有效。 codepen.io/anon/pen/zLwbQp -
因为这是复制粘贴错误... indentify() 在他的代码中,我没有注意到错字...
标签: javascript class ecmascript-6 extends prototypal-inheritance