javascript-react-patterns icon indicating copy to clipboard operation
javascript-react-patterns copied to clipboard

Change singleton pattern counter class

Open bpetermann opened this issue 2 years ago • 1 comments

Hi, the counter class gave me the following error messages:

  • counter is not defined
  • After initialization (this.counter = 0) "counter is read-only"

Removing Object.freeze and returning the instance in the constructor should resolve this issue.

Otherwise, as in the Objects example, counter can also be initiated outside the class: let counter = 0; After that, however, the "this" keyword would have to be removed from the methods.

Thanks!

bpetermann avatar Aug 19 '23 12:08 bpetermann

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fm-workshop-2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 19, 2023 0:55am

vercel[bot] avatar Aug 19 '23 12:08 vercel[bot]