Private Names and Methods

Kevin Smith khs4473 at
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.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list