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

Added private property #counter to allow internal edits with Object.freez()

Open ahelmi365 opened this issue 1 year ago • 1 comments

For data properties of a frozen object, their values cannot be changed since the writable and configurable attributes are set to false.

If we try to use the increment() or decrement() methods with Object.freez(), we get a TypeError says : Cannot assign to read only property 'counter' of object '#<Counter>' at Counter.increment"

Private properties do not have the concept of property descriptors. Freezing an object with private properties does not prevent the values of these private properties from being changed.

In my request, I've added the #counter property as private property. Now we can use the increment() and decrement() methods with Object.freez() with no errors.

ahelmi365 avatar Jul 07 '24 09:07 ahelmi365

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 Jul 7, 2024 9:49am

vercel[bot] avatar Jul 07 '24 09:07 vercel[bot]