Prototypal Chaining
Explore prototypal chaining in JavaScript, a key mechanism in object inheritance. Understand how objects access properties through their prototype links, enabling property lookup across a chain of prototypes until null is reached. This lesson helps you grasp how JavaScript uses prototype properties to support inheritance and property sharing among objects.
We'll cover the following...
Look at the following code snippet, which uses the [[Prototype]] property of objects:
Let’s delve into the details of the code above.
When the prototype property of Rectangle is set to Shape, it is able to access all the properties present in Shape. So, upon accessing, if a property is not found in the object, such as if the name property is not found in Rectangle, JavaScript will automatically take it from the prototype of the object, Shape. This is known as prototypal inheritance.
As seen from the code above, since the prototype of ...