OOP

Object Oriented Programming

OOP:

  • this

  • new keyword

  • Prototype

  • Classes

  • Inheritance

  • Object.Create()

  • Private vs Public

  • 4 principles of OOP.

Ex:
const dragon = {
    name: 'tanya',
    fire: true,
    fight() {
        return 5;
    },
    sing() {
        if (this.fire) {
            return `I'm ${this.name}, the breather of fire`;
        }
    }
};

In the above example, name and fire allows to track the state of the object and fight and sing methods allows us to manipulate the state of the object.

There are two object oriented programming in JavaScript.

  1. Prototypal Object Oriented Programming

  2. Class Object Oriented Programming

Reference's:

Last updated