JSFiddle - React, Tailwind, and code Playground
by Stafox
JavaScript
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()
{
this.name = 'unknown';
}
function Rabbit(name) {
this.name = name;
}
Animal.prototype.jump = function() {
console.log('jump ' + this.name);
}
extend(Rabbit, Animal)
// добавили в класс Rabbit методы и свойства
Rabbit.prototype.run = function() {
console.log('run ' + this.name);
}
// все, теперь можно создавать объекты
// класса-потомка и использовать методы класса-родителя
rabbit = new Rabbit('Bunny');
rabbit.run();
rabbit.jump();