JavaScript Prototypes and the Object Model (Summary)

Congratulations, you made it to the end of the course! Northbank Tool Library’s loan kit model now runs in JavaScript. The checkout app prints the same seven lines as the Python module. They start with audit[tag[KIT-17: drilling]] and the drilling kit’s tools, listed twice, and run through PRINT audit[tag[KIT-17: drilling]] to Tool count: 5.

Getting there meant finding a new home for each piece of Python’s object model. Python looks up attributes through classes and an MRO. JavaScript follows links between objects, and the classes you write build those links for you.

In this course, you learned how to:

  • Follow a property read from an object’s own properties up its prototype chain to Object.prototype and null
  • Tell a constructor apart from its .prototype object and read a class as the objects it builds
  • Predict where super starts looking, whatever object receives the call
  • Keep an inherited setter in the loop by assigning after super() instead of declaring a field
  • Use a well-known symbol such as Symbol.iterator only when its meaning is clear and honor its contract
  • Choose between a cooperative class layer and a part the object holds

A property read checks the object’s own properties first, then follows one link at a time until it finds the name or reaches null. A missing property reads as undefined rather than raising an AttributeError. Nothing is copied along the way, so changing kind on the defaults object reached the drilling kit at once. A plain assignment, by contrast, created an own property on the drilling kit, hiding the inherited one.

Read a Class as Its Prototype Objects

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.