If you want a soft private you should follow Sean's recommendation.

As for protected, you can do:

new Class({

  initialize: function(){

  },

  method: function(){

  }.protected()

});

If you call klass.method() from outside your class, you'll get an error.

As for private, your scheme is fine. You can also:

var Klass = (function(){

 var privateVariable;


 return new Class({
    initialize: function(){

    },

    method: function(){
       // privateVariable is only accessible here.
    }
 });

})();

On Fri, Jan 13, 2012 at 2:41 PM, Sean McArthur <sean.mons...@gmail.com>wrote:

> I'd recommend following Python practices on this:
>
> var Example = new Class({
>
>     _secret: 'hello'
>
> });
>
> It's not private like C or Java, but it says "There's no contract with
> this property."
>

Reply via email to