What is the benefit of having methods on the prototype instead of on instances?
Memory efficiency. Methods on the prototype are shared by all instances. 1000 instances share 1 method. If methods were on each instance (this.method = function() {}), 1000 instances would have 1000 copies of the method.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Prototype: Real-World Examples in JavaScript
All arrays inherit from Array.prototype. When you call arr.map(fn), JS looks for map on arr, doesn't find it, then finds it on Array.prototype. This is how all arrays share the same methods (map, filter, reduce, etc.).
const child = Object.create(parent). child inherits all properties from parent. This is direct object-to-object inheritance without constructors or classes. Useful for simple prototypal patterns.
A mixin is an object with methods that can be mixed into other objects: Object.assign(MyClass.prototype, SerializableMixin). This adds the mixin's methods to the class's prototype. It is composition over inheritance.
Still have questions?
Browse all our FAQs or reach out to our support team
