简体   繁体   中英

Call base prototype function

I have the following 2 objects:

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);

When I do the following

var foo = myPizza.foo();

It prints the following as expected:

pizza foo

How can I activate the base class and print "circle foo" from myPizza object?

pizza.prototype.foo.call(myPizza);   // outputs "circle foo"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM