This post is directed to haters who say:
1. Encapsulation? GET THIS🍑
2. Wanna abstract something? Easy😋
3. JS inherits from JAVA not only name, but 'extends' too🗑
4. Polymorphism. say less😋
Now you know your place, have a good one🤔
#OOP #stophating
there is no OOP in JS
1. Encapsulation? GET THIS
class Person {
#name;
constructor(name) {
this.#name = name;
}
getName() {
return this.#name;
}
}
const person = new Person('Alice');
console.log(person.getName()); // Alice
2. Wanna abstract something? Easy
class Car {
constructor(make, model) {
this.make = make;
this.model = model;
}
start() {
console.log(`Starting ${this.make} ${this.model}`);
}
}
const myCar = new Car('Toyota', 'Camry');
myCar.start(); // Starting Toyota Camry
3. JS inherits from JAVA not only name, but 'extends' too
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} makes a noise`);
}
}
class Dog extends Animal {
speak() {
console.log(`${this.name} barks`);
}
}
const dog = new Dog('Rex');
dog.speak(); // Rex barks
4. Polymorphism. say less
class Animal {
speak() {
console.log('Animal makes a noise');
}
}
class Dog extends Animal {
speak() {
console.log('Dog barks');
}
}
class Cat extends Animal {
speak() {
console.log('Cat meows');
}
}
const animals = [new Dog(), new Cat()];
animals.forEach(animal => animal.speak()); // Dog barks, Cat meows
Now you know your place, have a good one
#OOP #stophating
Please open Telegram to view this post
VIEW IN TELEGRAM