private name methods ?

Irakli Gozalishvili rfobic at
Thu Jun 21 11:54:08 PDT 2012


Some time ago I tried to get your intention about clojure protocols as I see them as better fit for JS and it's runtime than currently proposed classes. Although I can see that they may have implied too much new semantics. Recently I realized that private name objects can be used to do most of what protocols do with some boilerplate & performance penalties: 

I was wondering if it's a good idea to adjust "private name objects" proposal, since IMO it solves some of the ergonomics related issues that would prevent it from taking off:

API for calling private named methods is awkward: 
object[method](foo, bar) 

With private name methods it's natural:
method(object, foo, bar) 

API for accessing private names is ugly in comparison to normal properties:
var data = object[secret] 

With private methods it can be more natural:
var data = secret(object)

Private methods can provide not only more natural API (that feels similar to one used today), but there is much more to it, private methods provide semantics very similar to clojure protocols ( that arguably enable interesting ways to do polymorphism ( that IMO fits much better JS runtime than proposed classes. It is also fully harmonious with JS prototypical inheritance. It also solves issues inherent with diversity of community and libraries, as on may define protocol through the set of methods that can be independently implemented for set of libraries used. For example event dispatching protocol may be defined via on, off, emit private methods that later can be implemented without any conflict risks for DOM, jQuery, Backbone, etc... This will allowing one to use same set of privates methods regardless of which library data structure comes from. In a way monkey patching on steroids an
d conflict risks!

Thanks for you time & I'm looking forward to your feedback!
Irakli Gozalishvili

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

More information about the es-discuss mailing list