Instantiation patterns are ways to create something in JavaScript. JavaScript provides four different methods to create objects. Regardless of which method you use, every method will provide the following functionality:
- Create an object
- Create methods and properties for that object
There are four instantiation patterns in JavaScript. They are:
- Functional
- Functional-shared
- Prototypal
- Pseudoclassical
Functional Instantiation
With functional instantiation, we first create a function. Inside the function we create an empty object and add properties and methods to it. We then return this object.
Every time the function is called we will have access to the methods that were created. Here is an example of functional instantiation:
Pros:
For most people that are learning JavaScript this is the method that they learned for creating a new object. For anybody reading your code, it is easy to understand because all the functions are contained within the…