JS prototypical inheritance test
How do I make an js prototypical inheritance test?
What is a js prototypical inheritance test? How do you make a js prototypical inheritance test? This script and codes were developed by Jeremias Erbs on 08 December 2022, Thursday.
JS prototypical inheritance test - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>JS prototypical inheritance test</title> <script src="https://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ body { margin: 2em;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <pre class="logger"> *** Start logging ***<br></pre> <script src="js/index.js"></script>
</body>
</html>
JS prototypical inheritance test - Script Codes CSS Codes
body { margin: 2em;
}
JS prototypical inheritance test - Script Codes JS Codes
// A constructor is just a function that is called with the 'new' keyword.
// With doing so, you can refer to the created instance via 'this'.
// To add a method to all instances, add it to the constructor's prototype.
// create first constructor
var Mammal = function () { this.init = function (name) { this.name = name; log("Mammal name: " + this.name); } this.sound = "Graaawgh";
};
// add a talk method to first constructor
Mammal.prototype.talk = function() { log("Mammal says " + this.sound);
}
// create second constructor
var Cat = function() { this.sound = "Meow"; this.talk = function() { log("Cat says " + this.sound); }
};
Cat.prototype = new Mammal(); // make it a Mammal
Cat.prototype.constructor = Cat; // keep the constructor
// create instance of Cat
var kitty = new Cat;
kitty.init("Kitty"); // Mammal name: Kitty
kitty.talk(); // Cat says Meow
// create instance of Mammal
var someMammal = new Mammal;
someMammal.init("Olli"); // Mammal name: Olli
someMammal.talk(); // Mammal says Graaawgh
log("<br> *** Change Olli's sound: ***");
someMammal.sound = "Woohoo";
someMammal.talk(); // Mammal says Woohoo
kitty.talk(); // Mammal says Woohoo
log("<br> *** Check instanceof: ***");
log("Kitty is Mammal", kitty instanceof Mammal); // true
log("Kitty is Cat", kitty instanceof Cat); // true
log("Olli is Mammal", someMammal instanceof Mammal); // true
log("Olli is Cat", someMammal instanceof Cat); // false
log("<br> ***check constructor: ***")
log("Kitty is Mammal", kitty.constructor === Mammal); // false
log("Kitty is Cat", kitty.constructor === Cat); // true
log("Olli is Mammal", someMammal.constructor === Mammal); // true
log("Olli is Cat", someMammal.constructor === Cat); // false
//////////////////////////////////////////////
// create a logger to show things on screen //
//////////////////////////////////////////////
function log (content) { var output = document.getElementsByClassName("logger")[0], content = Array.prototype.slice.call(arguments).join(": "); output.innerHTML += content + "<br>";
};

Developer | Jeremias Erbs |
Username | badabam |
Uploaded | December 08, 2022 |
Rating | 3 |
Size | 2,436 Kb |
Views | 12,138 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Word combinator | 3,432 Kb |
Better jQuery event handler example | 2,928 Kb |
Circle through values in array | 1,903 Kb |
A 1x1 transparent base64 gif. | 1,942 Kb |
Animate SVG Smiley with AngularJS | 2,822 Kb |
Animate elements with fixed gradient | 4,406 Kb |
Button with stripe shadow | 3,602 Kb |
CSS3 Columns Example | 2,886 Kb |
Simple icon element with any centered content | 2,880 Kb |
Prototype pattern example | 2,526 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
HexMaze | Cantelope | 4,825 Kb |
CSS Social Media Icon | TychoBlender | 3,871 Kb |
Modular Flip Card | Bbodine1 | 4,009 Kb |
Free css icon set v2 - one div | Ben_jammin | 0 Kb |
Midterm dry run | Jds317 | 1,649 Kb |
Rotate Demo | Agelber | 3,061 Kb |
Guage | Roygwells | 5,653 Kb |
HEXAGON | Aurumlux | 1,684 Kb |
Toggle Time | Petebot | 5,345 Kb |
Dragonball Dragon Radar | DouglasGlover | 2,157 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!