JavaScript OO
How do I make an javascript oo?
What is a javascript oo? How do you make a javascript oo? This script and codes were developed by Mnicpt on 30 July 2022, Saturday.
JavaScript OO - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>JavaScript OO</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <script src="js/index.js"></script>
</body>
</html>
JavaScript OO - Script Codes JS Codes
/* OOPS: Encapsulation Inheritance Polymorphism Composition
*/
// UPDATE: (new way: ECMAScript 2015)
class Animal { constructor () { // private variables: Encapsulation var weight = 100; // public instance variables this.eyes = "blue"; this.hair = "white"; }
}
class Collar { constructor () { this.name = "Joe" this.phone = "217-555-1212" }
}
class Cat extends Animal { constructor () { this.collar = new Collar(); // Composition this.collar.name = "Fluffy"; this.collar.phone = "309-888-1212"; this.eyes = "brown"; } speak () { console.log("Purr"); }
}
// OLD WAY
Function.prototype.extends = function(func) { if (func instanceof Function) { this.prototype = Object.create(func.prototype); this.prototype = new func(); }
}
// Inheritance
var Animal = function() { // private variables: Encapsulation var weight = 100; // public instance variables this.eyes = "blue"; this.hair = "white";
}
var Collar = function() { this.name = "Joe" this.phone = "217-555-1212"
}
var Cat = function() { this.collar = new Collar(); // Composition this.collar.name = "Fluffy"; this.collar.phone = "309-888-1212"; this.eyes = "brown"; this.speak = function() { console.log("Purr"); }
}
Cat.extends(Animal);
var fluffy = new Cat();
console.log(fluffy);
console.log(Cat.prototype);
console.log(fluffy instanceof Animal);
console.log("eyes: " +fluffy.eyes);
console.log("hair: " +fluffy.hair);
fluffy.speak();
Developer | Mnicpt |
Username | mnicpt |
Uploaded | July 30, 2022 |
Rating | 3 |
Size | 1,904 Kb |
Views | 36,432 |
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 |
Graph Paper Background | 2,517 Kb |
Simple Grid | 4,606 Kb |
Plain JavaScript Calculator | 3,600 Kb |
Rotate Image | 1,843 Kb |
Graph API | 4,456 Kb |
Quick Sort | 7,584 Kb |
A Pen by mnicpt | 3,851 Kb |
Trinary Tree | 2,282 Kb |
Contact Snippet | 1,815 Kb |
Model View Sync | 1,733 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 |
Preloader | Rikki_Sixx | 2,815 Kb |
Ghost Buttons with CSS3 | Mithicher | 2,509 Kb |
3D Text in Sass | Bookcasey | 2,766 Kb |
Simple jQuery Slider | Jurbank | 2,874 Kb |
Elephants Full screen site | Orrinward | 3,981 Kb |
Em Test | Rodesco | 1,784 Kb |
Practice using Wixel | Emnk | 3,057 Kb |
Growing Root - Scroll control - CANVAS | Cjonasw | 2,342 Kb |
My three.js practice | Esambino | 3,203 Kb |
STAR WARS LIGHTSABER | Francoiscoron | 4,420 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!