Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8093655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:32:54+00:00 2026-06-05T20:32:54+00:00

I am playing about with Mootools class inheritance etc and I am trying to

  • 0

I am playing about with Mootools class inheritance etc and I am trying to call the base classes overridden methods with the .parent property (sry for the long code snippet).

var app = this.app = {},
    //ultimate base class
    Animal = new Class({
        initialize : function(param){
            this.age = param.age;
            this.name = param.name;
        },
        doStuff : function(param){
            alert("animal doStuff");
        }
    }),
    //herbivore functionality
    HerbivoreBehaviour = new Class({
        eat : function(){
            alert('Plants are scrumptious');
        }
    }),
    //carnivore functionality
    CarnivoreBehaviour = new Class({
        eat : function(){
            alert('Meat tastes gooood');
        }
    })
    //mammal base class
    Mammal = new Class({
        Extends : Animal,
        initialize : function(param){
            this.parent(param);
            this.numberOfNipples = param.numberOfNipples;
        },
        doStuff : function(){
            alert("mammal doStuff");
            this.doStuff.parent();
        }
    }),
    //reptile base class
    Reptile = new Class({
        Extends : Animal,
        initialize : function(param){
            this.parent(param);
            this.numberOfScales = param.numberOfScales;
        },
        doStuff : function(){
            alert('reptile doStuff');
            this.doStuff.parent();
        }
    }),
    //final top class animal->mammal-cow!
    //and it's a herbivore
    Cow = new Class({
        Extends : Mammal,
        Implements : HerbivoreBehaviour,
        initialize : function(param){
            this.parent(param);
            this.isMooCrazy = param.isMooCrazy;
        },
        doStuff : function(){
            alert('I am a cow');
            this.doStuff.parent();
        }
    }),
    //final top level class animal->reptile->mutantLizard!
    //and it's a carnivore
    MutantLizard = new Class({
        Extends : Reptile,
        Implements : CarnivoreBehaviour,
        initialize : function(param){
            this.parent(param);
            this.isDestroyingEverything = param.isDestroyingEverything;
        },
        doStuff : function(){
            alert('STOMP STOMP STOMP CRRRRRASH');
            this.doStuff.parent();
        }
    });

    app.run = function(){
        var daisy = new Cow({
                name : 'Daisy',
                age : 2,
                numberOfNipples : 6,
                isMooCrazy : true
            }),
            godzilla = new MutantLizard({
                name : 'Godzilla',
                age : 1123,
                numberOfScales : 123456,
                isDestroyingEverthing : true
            });

        daisy.eat();
        godzilla.eat();
        daisy.doStuff();
        godzilla.doStuff();
    };

the current output is correct from daisy.eat() and godzilla.eat() but then execution stops after the first print statement from daisy.doStuff() it doesn’t then call daisies parent class doStuff() method which is what I was hoping for. Could you tell me how I would call doStuff like this?

UPDATE:

I managed to fix he call sequence by replacnig this.doStuff.parent() with this.parent(). However this raised the question as to what ‘this’ is reffering to. I thought it would be the actual instance of the class ie. daisy or godzilla, but the use of this.parent() in the doStuff method would seem to imply, to me atleast, that ‘this’ is referring to the actual Function object which it is currently inside, unless calling the parent() method inside a function automatically looks for what method you are in and calls it’s first overridden method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:32:56+00:00Added an answer on June 5, 2026 at 8:32 pm

    right. well basically, all is good, that’s the good news. the only change required is swapping your this.doStuff.parent() to this.parent() all around.

    http://jsfiddle.net/dimitar/njQBN/

    seems to work fine.

    doing this.doStuff.parent() is not very DRY to begin with, and it also references a local property – which in the context of a class that Extends and Implements others with the same method – at the same time, will have … unexpected results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am playing about with Erlang and I am trying to write a simple
Currently playing about with KnockoutJS. Just trying to update an observable array from a
I have been playing about with LINQ-SQL, trying to get re-usable chunks of expressions
I've been playing about with isotope a bit http://isotope.metafizzy.co/demos/relayout.html and have been trying to
I have been playing about with a GUI today and trying add different elements
I am playing about just now trying to teach myself a little bit about
I've got a jQuery CSS Gallery setup, Just playing about with the styles etc
I've been playing about with the KineticJs JavaScript library and now I'm trying to
I've been playing about with the WorkItem objects from the Microsoft.TeamFoundation schemas in C#,
I’ve been playing about with wsp solutions and a question has occurred to me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.