- downside: memory overhead (duplicate methods for every instance)
- benefit: clarity
- downside: mutating closure variables + side effects
- lines 1 – 14: the constructor function
- line 2: create an empty object
- line 3: add an example ‘differentiator’ variable stored in closure
- lines 5 – 11: add methods directly to empty object
- line 13: return the new object
We can now create as many Example
instances as we want, all with its own copy of each method. It is as simple as var example = Example();
.