jsQuiz inheritance

by David McClelland

JavaScript

function Animal() {
this.sound = 'animal sound';
}

Animal.prototype.makeSound = function() {
alert(this.sound);
}

function Dog() {
this.sound = 'Woof Woof';
}

Dog.prototype = new Animal();

var dog = new Dog();
dog.makeSound();