JSFiddle - React, Tailwind, and code Playground
by henser
JavaScript
// Inheritance, scoping and prototype
function Animal() {
this.name = 'Bobby';
this.species = 'cat';
}
Animal.prototype.whatDoesItDo = function(noise) {
var sound = 'noiseous';
return (function(){
alert('The '+this.species+' named '+this.name+' makes a '+noise+' '+sound+'!');
})();
};
function Dog() {
Animal.call(this);
}
Dog.prototype = Object.create(Animal.prototype);
var bobby = new Dog();
bobby.species = 'dog';
bobby.whatDoesItDo('woof woof');
// Closure
/* function makeSomeNoise() {
var noise = "AAAAHHHH!!!";
function shout() {
alert(noise);
}
return shout;
} */
var myShout = makeSomeNoise();
myShout();
// Hoisting
/* bla = 2;
alert(bla);
var bla;
var bu;
alert(bu);
bu = 5; */