JavaScript OO

Developer
Size
1,904 Kb
Views
36,432

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 Previews

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();
JavaScript OO - Script Codes
JavaScript OO - Script Codes
Home Page Home
Developer Mnicpt
Username mnicpt
Uploaded July 30, 2022
Rating 3
Size 1,904 Kb
Views 36,432
Do you need developer help for JavaScript OO?

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!

Mnicpt (mnicpt) Script Codes
Create amazing blog posts with AI!

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!