Search⌘ K
AI Features

Managing Instance Types with species

Explore the use of Symbol.species in JavaScript for managing instance types in inheritance. Learn how to replace custom kindHint properties with Symbol.species to control which constructor creates derived objects, ensuring precise behavior in subclass methods like filter and concat.

We covered the implementation of static property kindHint for configuring the instance type in the Managing Instance Types Rules lesson. Let’s move onto the symbols in this lesson.

We may create our own symbol, for example, Symbol.for("KINDHINT"), but there’s already a predefined symbol for this purpose in JavaScript—Symbol.species.

Symbol.species

Symbol.species is used to convey the constructor to be used to create derived objects. Let’s ...