...

/

Managing Instance Types

Managing Instance Types

Learn about the instance type of an instance created by the base class method in JavaScript.

Suppose a method of your class, clone() for example, creates and returns an instance of its own type. Now, suppose you inherit from this class. A user of your derived class can automatically reuse the clone() method defined in its base class. However, when called on an instance of the derived class, should clone() return an object of the base type or the derived type?

In general, when using inheritance, if a method in the base class creates an instance, should that instance be of the base type or the derived type? 🤔

It’s a mark of an educated mind to say, “It depends!” ...

Access this course and 1400+ top-rated courses and projects.