On Mar 16, 2012, at 18:05, "David Bruant" 
<[email protected]<mailto:[email protected]>> wrote:

Le 16/03/2012 23:00, Rick Waldron a écrit :
On Fri, Mar 16, 2012 at 5:12 PM, Domenic Denicola 
<[email protected]<mailto:[email protected]>> wrote:
Just to contribute to this... er... fun-thread...

My team uses the closure pattern for our "classes" (i.e. no prototype methods 
at all), since we value encapsulation. I can't imagine we're alone.

For my own curiosity, can you point me to some examples where you are 
strategically avoiding the use of the prototype pattern?
When he needs actual encapsulation.
Unfortunately, methods on prototype require to have properties that are public.

If you avoid prototype methods, all your attributes and private methods can be 
shared by public method scopes.

David

Exactly. I am away from computer right now, so I cannot dig up examples from 
our codebase at work, but essentially we use the pattern described by Crockford 
in

http://www.crockford.com/javascript/private.html

And we use only "privileged" methods (on the instance), not "public" ones (on 
the prototype). This also neatly avoids binding problems via a single `var that 
= this` at the top of the constructor.

Here is an example from some of my own open-source code:

https://github.com/domenic/pubit/blob/master/lib/Publisher.js

(The `var that = this` in that particular example is unnecessary since no 
public methods call each other; it's just there as part of the boilerplate 
encapsulated-class pattern I always use.)

Hope this helps, despite being cobbled together on an iPhone.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to