Fundamentals

First, let us define some fundamentals required to understand a few concepts of oops. 

Classes

As a prototyping language javascript does not contain any class statement. Instead javascript uses functions as classes. 

Objects

Javascript has two types of objects, Core objects, and User-defined objects  

Core objects are a list of predefined objects in the javascript core; these functions have a global scope, i.e., they can be used anywhere in the project. 

Example: Math object

User-defined objects are defined using the new statement. User-defined objects cannot use the same names used by the core objects of javascript. 
 

Object Properties

An object-oriented programming language provides developers with four capabilities:

  • Encapsulation
  • Inheritance
  • Polymorphism
  • Aggregation

Inheritance

Inheritance is the ability of a class(class A) to acquire the properties another class(class B). Here class A is referred to as the child class and class B is regarded as the parent class. The child class inherits all the methods defined in the parent.

Encapsulation

Even though the child class can use the inherited methods, it does not need to know the inner working of those methods. Unless we need to change the operation, we do not need to define the method in the child class explicitly.

Polymorphism

The ability to define different methods in different classes with the same name is 'polymorphism.' Unless the class has a parent-child relationship with another class, javascript restricts the scope of these methods to the class. Thus making polymorphism possible.

Abstraction

Abstraction is the ability of the language to hide most of the details only to show the essential features of the project. Hence, Abstraction improves the understandability and the readability of the code. We apply abstraction in java using prototypes.

Try

Try