Listing Every Kind of Own Key
In this lesson, you find out which listing shows which of the proof card’s own keys, and which one
shows them all. The card has a title and a price, the read-only id you set with its flags, and a
tag saved under the SOURCE symbol, card[SOURCE] = "proof desk". Before the card goes into a
customer’s export, the desk needs to know which keys each tool sees, its own tag included.
In Python, vars(card) lists every attribute on the instance, and json.dumps(vars(card)) writes
them all out, _id included: the underscore is only a naming convention. In JavaScript,
Object.keys(card) and JSON.stringify(card) give only the title and the price. The id was made
non-enumerable, but the symbol tag, added with an ordinary assignment, is missing too.
Each listing asks two separate questions about a key: is it enumerable, and is the key a string or
a symbol? On the card, title and price are enumerable strings, id is a string that isn’t
enumerable, and the tag is an enumerable symbol. Object.keys() and JSON.stringify() want a yes
to both questions. Python’s vars() asks neither: Python has no enumerable flag, and every
attribute name on the instance is a string.
Here’s the whole listing.js, with one listing per line from line 9 on: