The JavaScript Object Model: Properties, Descriptors, and Freezing (Summary)

Congratulations, you made it to the end of the course! Harbour Prints’ proof card export now runs in JavaScript. It prints Proof P-17: Harbour, 25 copies and {"id":"P-17","title":"Harbour","copies":25}, the same two lines as the Python script.

Getting there meant looking past an object’s values to the rules around them: where each property lives, the flags it carries, whether it stores a value or computes one, what kind of key it has, and how far a lock reaches. Python spreads those answers across the class, __dict__, and wrapper types such as MappingProxyType. In JavaScript, most of them sit on the object itself.

In this course, you learned how to:

  • Tell a property an object owns from one it finds through its prototype, with Object.hasOwn(), Object.keys(), in, and for...in
  • Read a property’s descriptor and set its writable, enumerable, and configurable flags on purpose with Object.defineProperty()
  • Choose between a snapshot that keeps a getter’s value and a copy that keeps the getter itself
  • Tag an object with a Symbol() key and pick the listing that shows the keys you’re asking about
  • Pick Object.preventExtensions(), Object.seal(), or Object.freeze() by the flags each one sets, and lock each nested object explicitly
  • Build a public report by naming its fields instead of dumping the object

Separate Owning From Finding

In Python, card.category finds "print" on the Card class, while vars(card) holds only what the instance stores. The JavaScript card comes from Object.create(defaults), so card.category follows the prototype link to a plain object instead of a class.

Lookup and ownership are different questions. "category" in card walks the link and gives true, like hasattr(). Object.hasOwn(card, "category") asks the card alone and gives false. Object.keys(card) lists only [ 'title', 'price' ], while a for...in loop picks up category too. For your own data, use Object.keys().

Set Every Flag on Purpose

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.