JSFiddle - React, Tailwind, and code Playground
by Tony C
JavaScript
var Animal = (function() {
var species = '';
return {
getSpecies: function() {
return this.species;
}
}
})();
// Chain the prototype back to animal
var myDog = Object.create(Animal);
// Add a new function to initialize the object
myDog.init = function(name, age) {
this.species = 'dog';
this.name = name;
this.age = age;
}
// Add a new function to call the dog
myDog.call = function() {
console.log( "Here, " + this.name );
}
// Initialize our new object
myDog.init('Fido', 4);
// Call each method on the object
myDog.call();
console.log(myDog.getSpecies());