JSFiddle - React, Tailwind, and code Playground
by danShumway
JavaScript
//Let's make some interfaces to apply to our object.
//An animal, which can speak.
function Animal(myNoise){
this.noise = myNoise;
this.alive = true;
//All animals can make noise!
this.makeNoise = function(){
alert("I make a noise: " + this.noise);
}
}
//A cyborg which can set its phazors.
function Robot(){
this.phazors = "hug";
//Robots can set their phazors.
this.setPhazors = function(){
alert("Set phazors to " + this.phazors + "!");
}
}
//Lets make an object to inherit from these interfaces.
function CyborgCat(){
//Call both the parents.
Animal.call(this, "meow");
Robot.call(this);
//Just to make sure we inherit.
this.isAlive = function() {
alert(this.alive);
}
}
//Make a CyborgCat and call its methods.
var myCyborgCat = new CyborgCat();
myCyborgCat.makeNoise();
myCyborgCat.setPhazors();
myCyborgCat.isAlive();