On Sat, 17 Mar 2012 00:18:48 +0100, David Bruant <[email protected]> wrote:
A Person knows one secret and has methods like .eat(), .walk()... There is no method in the Person interface to reveal the secret either directly or indirectly. A ComputerSavvyPerson is a Person, but has an additional .getMD5HashedSecret() method which returns the hashed secret. A StupidPerson is a person with a method .tellSecret()
For example, see <https://gist.github.com/2053624>. I don't see what's wrong with using closures for hiding variables, when necessary. [snip]
This is a piece of cake with Java's protected. It is much convoluted in JavaScript. I think this kind of problem being hard to solve in JavaScript is the reason why so many frameworks like Node.js make the choice to expose their internals.
I think "exposing the internals" is more "idiomatic" in JavaScript to expose the internals rather than trying to hide them, similarly to how I think it's idiomatic to assume the correct types of parameters rather than manually checking their types (in many cases at least, especially for internal functions). The "exposing all properties" flows well with how prototypal inheritance works, but even disregarding that we also see "exposed internals" in other dynamic languages than JavaScript, such as Python.
David
Jonas _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

