JSFiddle - React, Tailwind, and code Playground
by William Sena
HTML
<div id="results">
</div>
CSS
body{
font-family: "Verdana";
}
JavaScript
var Animal = function Animal(){};
Animal.prototype = {
setResult: function setResult(message){
var result = document.createElement('p');
result.innerHTML = message + '<br/>Strength: ' + String(this.strength);
document.getElementById("results").appendChild(result);
}
};
var Lion = function Lion(){};
Lion.prototype = {
strength: 10,
name: 'Lion',
roar: function roar(){
this.setResult(this.name + ' Rooooaaarrrrrr.');
}
};
var Falcon = function Falcon(){};
Falcon.prototype = {
strength: 2,
name: 'Falcon',
fly: function fly(){
this.setResult(this.name + ' flying.');
}
};
var LionFalcon = function LionFalcon(){};
$.extend(Lion.prototype, new Animal(), true);
$.extend(Falcon.prototype, new Animal());
$.extend(LionFalcon.prototype, new Falcon(), new Lion(), new Animal(), true);
var lion = new Lion();
var falcon = new Falcon();
var lionFalcon = new LionFalcon();
lionFalcon.name = 'Lion Falcon';
(function(){
function roar(){
for(var i=0, c=arguments.length; i<c; i++){
if(arguments[i].roar){
arguments[i].roar();
}
}
}
function fly(){
for(var i=0, c=arguments.length; i<c; i++){
if(arguments[i].fly){
arguments[i].fly();
}
}
}
roar(lion, falcon, lionFalcon);
fly(lion, falcon, lionFalcon);
})();