January 2020
Intermediate to advanced
548 pages
13h 36m
English
The Constructor pattern uses a singular constructor and then manually fills its prototype with methods and properties. This was the traditional approach for creating classical OOP-like classes in JavaScript before the class definition syntax existed.
Typically, it begins with the definition of a constructor as a function declaration:
function Book(title) { // Initialization Logic this.title = title;}
This would then be followed by assigning individual methods to the prototype:
Book.prototype.getNumberOfPages = function() { /* ... */ };Book.prototype.renderFrontCover: function() { /* ... */ };Book.prototype.renderBackCover: function () { /* ... */ };
Or it would be followed by replacing the entire prototype with an object ...
Read now
Unlock full access