3 ms·
public/private is the most pointless distinction ever invented. Enforced privacy makes reuse nearly impossible. That said, I don't really think Javascript is
by jrockway 17y ago
public/private is the most pointless distinction ever invented. Enforced privacy makes reuse nearly impossible.
That said, I don't really think Javascript is all that special. Prototype OO sucks.
- mhansen 17y agoCan you explain why you think x sucks/is pointless?
- jrockway 17y agoEnforced privacy limits reuse but doesn't prevent any particular class of bugs (calling random private methods is no worse than calling random public methods; you should feel equally bad about both). Prototype OO precludes introspection. You have "an object", and that's as much as you can ever know.
- wvenable 17y agoYou're looking at enforced privacy from the callers perspective not the callee perspective. For the callee, the benefit is you can change or remove any private methods or private data structures and be guaranteed not to affect any callers. It's the benefit of basic encapsulation. Although I completely agree with you about Prototype OO it doesn't necessarily preclude introspection. You can find out what kind of object it is (by looking at the constructor property) and you can iterate the methods and properties. Introspection is not a problem. But there are no guarantees -- if you find out that your object is a "bicycle" there is no guarantee it has a "pedal" method even if it had one on creation.