After viewing the first few lectures of Will Sentance’s OOP course, I understood why it is more memory-efficient to rewrite my createArray() function using object-oriented programming.
By hiding the array object class methods of pop(), push(), shift() and unshift() in a prototype object, I would be able to more efficiently create new instances of this array object using the “new” / “this” keywords, without rewriting all these methods in each instance.
A few scribbled notes from Will’s Lecture:
The original class object has property: “prototype,” which is an object of methods accessible to all instances of that object.
The “new” keyword creates an instance that inherits all prototype properties. We refer to it with “this” keyword, and its inherited properties: “__ proto __”
__proto__ is a hidden bond to original class object’s properties
this.__proto__ = classObject.prototype