Object Prototypes
Learn how JavaScript uses object prototypes and the prototype chain for property lookup. Understand key properties like __proto__, methods like hasOwnProperty, and safer functions such as Object.getPrototypeOf and Object.setPrototypeOf to manage prototypes effectively.
In this lesson, we’ll cover a lot of seemingly unrelated topics. They’re all necessary for understanding inheritance in JavaScript. We’ll tie it all together in the next lesson.
Object, Array, and Function
JavaScript gives us access to three global functions: Object, Array, and Function. Yes, these are all functions.
You don’t know it, but every time you create an object literal, the JavaScript engine is effectively calling new Object(). An object literal is an object created by writing {}, as in var obj = {};. So an object literal is an implicit call to Object.
Same goes for arrays and functions. We can think of an array as coming from the Array constructor and a function as coming from the Function constructor.
Object Prototypes
All JavaScript objects have a prototype. Browsers implement prototypes through the __proto__ property and this is how we’ll refer to it. This is often called the dunder proto, short for double underscore prototype. Don’t EVER reassign this property or use it directly. The MDN page for ...