Object Prototypes
We'll discuss the '__proto__' property present on objects. It's the tool that lets us implement inheritance and is a vital part of JavaScript.
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.
console.log(Object); // -> [Function: Object]console.log(Array); // -> [Function: Array]console.log(Function); // -> [Function: Function]
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 ...