JSFiddle - React, Tailwind, and code Playground
by Hal_9100
JavaScript
/**
* Only Bird must inherit this class
*/
var Animal = function() {
this.className = 'Animal';
};
Animal.prototype.sayClassName = function() {
console.log('I am a '+ this.className);
};
Animal.prototype.isAnimal = function() {
console.log('I am an animal');
};
/**
* Both Boomerang and Bird must inherit this class
*/
var Flying_object = function() {
this.className = 'Flying_object';
};
Flying_object.prototype.sayName = function() {
console.log('I am a '+ this.className);
};
Flying_object.prototype.fly = function() {
console.log(this.className +' can fly');
}
var Bird = function() {
this.className = 'Bird';
}
Bird.prototype = new Animal(); //----> Bird should inherit both Animal and Flying_object
Bird.prototype = new Flying_object(); //----> but Flying_object overloads Animal instead of just adding up
Bird.prototype.sayName = function() {
console.log('I am a '+ this.className);
};
var Boomerang = function() {
this.className = 'Boomerang';
}
Boomerang.prototype = new Flying_object();
Boomerang.prototype.sayName = function() {
console.log('I am a '+ this.className);
};
/**
* Instating...
*/
var boomerang = new Boomerang();
var bird = new Bird();
boomerang.sayName();
boomerang.fly();
bird.sayName();
bird.fly();
bird.isAnimal(); //---> Uncaught TypeError: bird.isAnimal is not a function