派生类的构造函数返回基类的实例。
以下代码解释了我的问题:
这怎么可能实现呢?
以下代码解释了我的问题:
// Vector is defined by an external module (Unreal.js)
class TestB extends Vector {
constructor() {
super();
}
Log() {
console.log("" + this);
}
}
console.log(new TestB() instanceof TestB) // returns false !!! why ???
console.log(new TestB() instanceof Vector) // returns true...
class TestA extends Array {
constructor() {
super();
}
Log() {
console.log("" + this);
}
}
console.log(new TestA() instanceof TestA); // returns true, all is good
这怎么可能实现呢?
console.log(new TestB() instanceof TestB)
返回 true。 - shilchnew
将使用该对象并丢弃它创建的实例。 - Jonathan Lonowski