prototype-pattern
Installation
SKILL.md
Prototype Pattern
The prototype pattern is a useful way to share properties among many objects of the same type. The prototype is an object that's native to JavaScript, and can be accessed by objects through the prototype chain.
In our applications, we often have to create many objects of the same type. A useful way of doing this is by creating multiple instances of an ES6 class.
When to Use
- Use this when many objects need access to the same methods without duplicating them
- This is helpful for understanding JavaScript's inheritance model and ES6 classes
Instructions
- Use ES6 classes to automatically add methods to the prototype
- Use
Object.create()to create objects with a specific prototype - Leverage the prototype chain for inheritance (
extendskeyword in ES6 classes) - Understand that properties on the prototype are shared and not duplicated per instance