How do array methods work via prototypes 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.).
Explore This Question
Search for additional explanations using these tools:
More FAQs in Prototype: Real-World Examples in JavaScript
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.
class ApiClient { get(path) {} } puts get on ApiClient.prototype. All instances (new ApiClient()) inherit get from the prototype. This is memory-efficient: one get function shared by all instances.
Still have questions?
Browse all our FAQs or reach out to our support team
