Наследование на классах. Функция extend
function extend(Child, Parent) {
var F = function() { }
F.prototype = Parent.prototype
Child.prototype = new F()
Child.prototype.constructor = Child
Child.superclass = Parent.prototype
}
function Animal(name) {
this.name = name;
}
Animal.prototype.getName = function() {
return this.name;
}
function Dog(name){
this.name = name;
}
extend(Dog, Animal);
Dog.prototype.bark = function () {
return ('Dog ' + this.getName() + ' is barking');
}
var dog = new Dog('Balto');
console.log(dog.getName()); //Balto
console.log(dog.bark()); //Dog Balto is barking