Under the Hood: Objects and Prototypes
Understand how JavaScript's object-oriented model uses prototypes instead of traditional classes. Learn about prototype chaining, delegation, and how JavaScript classes differ from class-based languages to build a solid foundation in JavaScript's unique approach.
We'll cover the following...
If you come from another programming background, chances are you already encountered classes and feel familiar with them. But as you’ll soon discover, JavaScript classes are not quite like their C++, Java, or C# counterparts.
JavaScript’s object-oriented model
To create relationships between objects, JavaScript uses prototypes.
In addition to its own particular properties, any JavaScript object has an internal property which is a link (known as a reference) to another object called its prototype.
When trying to access a property that does not exist in an object, JavaScript tries to find this property in the prototype of this object. Here’s an example (borrowed from Kyle Simpson’s ...