为什么这不起作用?
function Component(actor) {
this.actor = actor;
//...
}
Component.prototype.run = function() {
console.log("Inheritance Error: Component.run()");
};
function Intersection(actor) {
if (actor !== undefined) {
Component.call(this, actor);
...
}
}
Intersection.prototype = new Component();
Intersection.prototype.run = function() {
//...
};
function FloorIntersection(actor, list) {
Intersection.call(this, actor);
...
}
FloorIntersection.prototype = new Intersection();
var fi = new FloorIntersection(actor, list);
fi.run();
当我尝试调用时,它给了'undefined不是函数':fi.run()。但是,如果我这样做
var i = new Intersection(actor);
i.run();
然后它有效。
令人难以置信的令人沮丧,因为我在其他地方有完全相同的结构(ZachCharacterView - > Sprite - > Component),它的工作正常。