We've seen in previous recipes how to avoid having properties overridden. There are situations where we might not want a property to be read. Recall the Object.entries
method, which creates an iterator of all the properties and values on the object. Well, that's not precisely true. It creates an iterator of all the enumerable
properties.
In this recipe, we'll see how to create properties that won't be included in the iterator.
This recipe assumes you already have a workspace that allows you to create and run ES modules in your browser. If you don't, please see the first two chapters.
- Open your command-line application and navigate to your workspace.
- Create a new folder named
06-07-non-enumerable-props
. - Copy or create an
index.html
that loads and runs amain
function frommain.js
.
- Create a
main.js
file with amain
function that creates an object with key-value pairs of books and authors:
// main.js export function...