Grokking Advanced JavaScript
Vote

0% completed

​

Object Prototypes

Create an object with a single property, and it can already call a method that you never wrote.

[object Object] false true

The vehicle object has only one property of its own, wheels. The call vehicle.hasOwnProperty("toString") confirms that toString is not stored on it. The call still works because vehicle is linked to a second object, Object.prototype, and toString is stored there.

The object that another object is linked to is called its prototype. When the code reads a property, JavaScript first looks at the object itself

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content