Search⌘ K
AI Features

Challenge: Decorator Pattern

Explore how to use the Decorator Pattern to enhance JavaScript objects with multiple customizable properties. This lesson guides you through designing and modifying superheroes to have various superpowers using structural design patterns, improving your ability to solve interview challenges efficiently.

Problem statement

The code below implements the functionality that customizes superheroes for a game. If you study the code below, you’ll see that every superhero has a power. However, you can also create superheroes that have the following in addition to the power:

  • a sword

  • ...