Timeline for Why do we need private variables?
Current License: CC BY-SA 3.0
4 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 1, 2024 at 1:14 | comment | added | NickJ | This is just why 'this' and OOP should not be used in JavaScript or anywhere else. No one should be creating persistent state hidden in objects to be used later after invocation. This style of programming was broken from inception. | |
| May 9, 2019 at 20:45 | comment | added | Jeffrey Sweeney | @immibis Perhaps, and maybe I should have elaborated more in the answer. But access to properties can open the door for violating some OOP principles such as open-closed principle or LoD, as you're potentially exposing implementation details. 'course to your point it depends on what the property is exactly. Most languages use objects as references, and when references of objects get passed around and fellow devs quietly change properties, it can be REALLY hard to debug. IMO it's much easier and more extendable to work with methods if you have a class instance. | |
| May 9, 2019 at 2:18 | comment | added | Stack Exchange Broke The Law | It's not obvious why alerting 3 would be an "uh oh!" in this case. Maybe that's what the programmer wanted to happen. | |
| Apr 10, 2012 at 5:52 | history | answered | Jeffrey Sweeney | CC BY-SA 3.0 |