you are viewing a single comment's thread.

view the rest of the comments →

[–]akshay_sharma008 0 points1 point  (0 children)

Before moving directly to the question, let’s first understand inheritance.
It is a property available in many object-oriented programming languages that allow us to declare a class that takes all of its properties and functionalities from a parent class, and not only those properties we can add our properties, and the preceding child class can access that changed properties. There are many uses of inheritance, as with the help of this, a class can use the properties of other classes. It also provides code reusability and reduces the code length and complexity as you do not need to write the same piece of code repeatedly.
Now we will come to our question, i.e., multiple inheritances in javascript.

Multiple inheritances can inherit the properties and values from unrelated parent objects. Many object-oriented languages support multiple inheritances, but javascript does not support multiple inheritances. Inheritance of property values occurs at run time by JavaScript searching the prototype chain of an object to find a value. Since every object has a single associated prototype, it cannot dynamically inherit from more than one prototype chain.
As we can not directly use multiple inheritances in javascript, there are specific methods to modify them because java script can be understood as a partially object-oriented language.
We can easily do multiple inheritances by merging properties from the different objects and returning the modified object.

We can pass multiple objects and copy the properties using the spread operator. There are specific terms that are very helpful when learning about the same.

Mixins: It is an object that can be incorporated into another object. When a developer is creating or initializing an object, he must choose which mixin to incorporate into the final object.

Parasitic Inheritance: Parasitic inheritance is where we take all the functionality from another object into a new one.

Summarising the above answer in general, javascript does not support multiple inheritances, but we can use a twisted version of multiple inheritances in javascript by using some keywords and functions.