JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://cdn.crafty-modules.com/crafty-DEBUG.js"></script>
JavaScript
Crafty.init(100,100);
Crafty.scene("InheritanceExample", function()
{
Crafty.background("#000");
function Mammal(name){ //define a javascript class
this.name=name; }
Mammal.prototype.toString = function(){ //define a method of the class
return "Mammal: "+this.name; }
//Inheritance example
Cat.prototype = new Mammal(); //Cat inherits from Mammal class
Cat.prototype.constructor = Cat; //otherwise instances of Cat would have a constructor of Mammal
function Cat(name){
this.name=name; }
Cat.prototype.toString = function(){
//Cat's toString method overwrites Mammal's toString method
return "Cat: "+this.name; }
//We can check by printing the name:
var myMammal = new Mammal("Mr. Fancypants");
var myCat = new Cat("Mr. Meow");
console.log( myMammal );
console.log( myCat );
})
Crafty.scene("InheritanceExample");