我有以下两个对象:
function circle(radius){
this.radius = radius;
this.foo = function (){
return "circle foo";};
return true;}
function pizza(){
this.foo = function (){
return "pizza foo";};
return true;}
pizza.prototype = new circle(9);
当我执行以下操作时
var foo = myPizza.foo();
按预期打印以下内容:
pizza foo
如何激活基类并打印" circle foo"来自myPizza
对象?
答案 0 :(得分:2)
pizza.prototype.foo.call(myPizza); // outputs "circle foo"