private attributes in objects

Brendan Eich brendan at mozilla.com
Sun Oct 11 12:52:43 PDT 2009


On Oct 11, 2009, at 12:23 PM, memolus at googlemail.com wrote:

> Currently I do use such kind of prototypes:
>
> person = new function(name) {
>  this.name = name;
> }
> person.prototype = new function() {
>  /* Private */
>  var id;
>
>  /* Public */
>  this.name = "";
>  this.age = 0;
>  this.location = "US";
> }

This sketch could use a function-valued property of this to use the  
private id member, for motivation.


> The problem is I won't be able to use getter and setter when the new
> Ecmascript arrives.

Sorry, I don't know what you mean. What in ES5 prevents you from using  
which getter or setter syntax?

/be

> But if I switch to object definitions for
> prototype I won't be able to use private attributes anymore.
> I propose to allow
>
> person.prototype = {
>  /* private */
>  var id,
>
>  /* public */
>  name: "",
>  age: 0,
> location: "US"
> }
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list