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 |
Rotate Image | 1,843 Kb |
Solve Intersecting Lines | 1,792 Kb |
JavaScript Aspect | 1,648 Kb |
Apple Playing Cards | 4,618 Kb |
Balanced Binary Search Tree | 2,313 Kb |
First 100 Prime Numbers | 1,615 Kb |
Move Cell in Grid | 3,290 Kb |
A Pen by mnicpt | 3,851 Kb |
Fading Divider | 1,728 Kb |
3,268 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 |
Konami Code Easter Egg | Teolitto | 3,051 Kb |
Feedback Page | TessDiNapoli | 2,836 Kb |
Header | Er40 | 1,542 Kb |
Highbrow Basic HTML Lesson 8 | Kimlarocca | 2,094 Kb |
IbrahimJabbari-Effect14 | Ibrahimjabbari | 1,919 Kb |
Flip test | Madhes | 1,635 Kb |
Simple CSS loader. | Cabrera | 2,574 Kb |
Atom | Bhlaird | 1,932 Kb |
A form arranged using automatic placement. | Vikasford | 2,103 Kb |
Social buttons | Flacu | 2,022 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!