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>";
};
![JS prototypical inheritance test - Script Codes](http://shots.codepen.io/badabam/pen/CIdKo-512.jpg)
Developer | Jeremias Erbs |
Username | badabam |
Uploaded | December 08, 2022 |
Rating | 3 |
Size | 2,436 Kb |
Views | 12,144 |
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 |
Prototype pattern example | 2,526 Kb |
Word combinator | 3,432 Kb |
Image and text hover effect with filter and inline SVG | 3,797 Kb |
Animate SVG Smiley with AngularJS | 2,822 Kb |
Open and slide out content | 3,829 Kb |
Simple page for beginners lessons. | 3,068 Kb |
CSS3 Columns Example | 2,886 Kb |
A Typing Lessons App | 3,783 Kb |
Shopping cart animation | 0 Kb |
Stiftung Warentest Signet | 5,371 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 |
Sticky Navbar | Phantomesse | 5,106 Kb |
SVG Animation | Thepheer | 4,793 Kb |
Siema - add pagination to prototype | Pawelgrzybek | 2,575 Kb |
Kudos Please | TimPietrusky | 6,624 Kb |
RequestAnimationFrame | Martin-banks | 2,541 Kb |
Very Simple Slider | Doodlemarks | 2,682 Kb |
Sony Xperia Z3 Flat MockUp | Dapinitial | 4,379 Kb |
CSS Grid Overlay | Cliffpyles | 3,090 Kb |
Slides-07-1 POSITION | Exhtml | 1,909 Kb |
Simple checkbox style | Vncnz | 2,628 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!