Private Names and Methods

Kevin Smith khs4473 at gmail.com
Fri Apr 6 12:18:34 PDT 2012


>
> As Allen mentioned, I think it would really help if you could show, say,
> real Java (or C# or C++) code and explain what it can do that JavaScript +
> private names can’t.
>

(Sorry for that double-post, BTW)

I can't : )

It's an abstract guarantee.  Private methods (in Java let's say) give me
the guarantee that I can refactor at will with them without any externally
visible changes.  Privately named methods in JS do not.

Look at it this way:  if I have a method that looks like this:

    private helperMethod() { ... }

and it's called from another method like this:

    toString() { this. at helperMethod(); }

someone coming from Java or C# is going to expect a nonvirtual method
invokation.  See the Java spec for details [1].  OK - everything is dynamic
in JS, so they're just "confused", right?  Why even invite that confusion
with misleading syntax?

"private" syntax isn't a part of the current class proposal, I know.  I'm
just trying to think ahead - and to strike at the heart of what a "class"
in JS ought to be.


kevin

[1]:  http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120406/4a2c48f1/attachment.html>


More information about the es-discuss mailing list