Hacker News new | ask | show | jobs
by doomslice 5004 days ago
As you suggest, there are several schools of thought about how best to provide class-style programming. By using a closure instead of prototypes, you can have "true" private properties and functions. If you use prototype, you'll need to use a convention to mark something as private and hope the developers respect that (marking it with an underscore is common). In my experience, someone will ignore the convention and then something will break when you change or remove your "private" variable.
2 comments

If the code was using those or other advantages of the pattern (like easier subclassing, methods already bound to the instance, etc) consistently, it would make sense. As it is, it just does ugly things like using 'I' and 'this' without any thought or pattern I can discern.
Style is one thing, but if you use closures, you have to be a lot more careful about memory leaks.