Skip to content

Problem in Chapter 04.0, line 351 #62

Open
@stefanos82

Description

@stefanos82

I'm currently reading the PDF (nice work by the way!) and when I tested the code, line 351 worked which baffled me; after a couple of reads, I have realized I didn't have 'use strict'; at the very top of my file, which is not mentioned anywhere in the book.

Let's try to test this.
```js
new Logger("OK"); // throws error
new Logger(LogLevel.Debug); // works fine
new Logger(); // works fine
let logger = new Logger(LogLevel.Warn);
logger.level; // returns the `level` because of the getter `level()`
logger.#level; // throws error
logger.#level = LogLevel.Warn; // throws error
logger.level = 10; // throws error
```
Perfect! This all looks really good. We are confident that neither clients nor our own library's code will affect the internals of the library. Please note that only the `#level` member variable can be changed from within the class Logger's scope, which is exactly what we want.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions