Dor Cohen
Dor Cohen

Reputation: 17080

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?

Upvotes: 0

Views: 47

Answers (1)

xiaoyi
xiaoyi

Reputation: 6741

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

Upvotes: 2

Related Questions