Jan 24

Meh;

var Dog = function() {

    this.say = function( name ) {

       return name;

    }

};

var Animal = function() {

    this.inherit = Dog;
    this.inherit();

};

var pet2 = new Animal();

pet2.say("bob");

Something about writing on a whiteboards.

Of course, there’s load of different ways you could write this, meh.

  • Share/Bookmark

3 Responses to “Quick and dirty JavaScript ‘class’ inheritance”

  1. Michal says:

    From this example it seems you haven’t understood the inheritance concept in Javascript. Please review the code and I’m sure you will find the mistake.

  2. danj says:

    Why? Because I haven’t written it out with a proper construct method?

    I should probably change the title to ‘quick and dirty inheritance’.

  3. danj says:

    I need to write an article about class inheritance in JavaScript when I’ve got the time, there’s not enough hours in the day though :(

Leave a Reply

preload preload preload