Javascript-OOPs(Part4)-Polymorphism- (10)

  

👉Javascript with OOPs (Polymorphism)


Polymorphism is possible only with strongly typed languages, we cannot implement it in Javascript since we cannot declare strongly typed variables, and datatypes of variables are decided at runtime.


We have achieved a bit of polymorphism while implementing inheritance, where in "cust" object first refers to the "Customer" class and then to the "CustomerChild" class, but still direct polymorphism is not available. Javascript variables are dynamic and they are created based on the datatype of the right-hand side value.


To summarize:

1)You can create a class by using a function. You have a new keyword to create an instance.

2)You can define private and public methods by using/not using the "this" keyword.

3)Function inside a function is a closure. Closures are the core while implementing classes and objects in javascript.

4)Use Closures to create private methods, if you want to expose the method use "this".

5)If you want to implement "Inheritance" use "prototype".

6)Though it is possible logically, it is not advised to implement Abstract, Interface, and Polymorphism in Javascript.

7)Javascript is a lightweight object-based language, it is not advised to implement complicated OOPs concepts within it.

Comments

Popular posts from this blog

Javascript-OOPs(Part2)-AbstractionAndEncapsulation- (8)

Javascript-OOPs(Part1)-Objects - (7)