Prototype Property of Constructor Functions
What you'll learn: How every constructor function has a special prototype property that automatically becomes the __proto__ of instances created with new.
The Built-In Connection
When you define a constructor function, JavaScript automatically gives it a prototype property. This isn't just any property—it's the blueprint that all instances will share. When you use new with that constructor, the newly created object's __proto__ is set to point to the constructor's prototype property.
Think of it like a factory stamp: every constructor function gets a stamp (its prototype property), and every product (instance) that comes off the assembly line carries an impression of that stamp (its __proto__ points to the constructor's prototype).
How It Works
function Car(make) {
this.make = make;
}
// Every function automatically has a 'prototype' property
console.log(typeof Car.prototype); // "object"
const myCar = new Car("Toyota");
// The instance's __proto__ points to Car.prototype
console.log(Object.getPrototypeOf(myCar) === Car.prototype); // true
When you add methods to the constructor's prototype, all instances can access them:
Car.prototype.drive = function() {
return `${this.make} is driving`;
};
console.log(myCar.drive()); // "Toyota is driving"
Why This Matters
This mechanism is how JavaScript implements shared behavior. Instead of every instance having its own copy of methods, they all share the same methods from the constructor's prototype. This saves memory and enables inheritance patterns.
Key Takeaway: Every constructor function has a prototype property that becomes the __proto__ of all instances created with new, establishing the prototype chain and enabling shared methods.