private attributes in objects

# memolus at googlemail.com (16 years ago)

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"; }

The problem is I won't be able to use getter and setter when the new Ecmascript arrives. 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" }

# Brendan Eich (16 years ago)

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?

# memolus at googlemail.com (16 years ago)

Thanks for your answer.

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

Does your expression "a function-valued property of this" mean "method"?

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

You're right, there's the complex "defineProperty" methode I could use, but they are not so handy. Anyway why shouldn't I be able to set private attributes in {}-styled object definitions?

# Brendan Eich (16 years ago)

On Oct 11, 2009, at 1:28 PM, memolus at googlemail.com wrote:

Thanks for your answer.

This sketch could use a function-valued property of this to use the
private id member, for motivation. Does your expression "a function-valued property of this" mean
"method"?

Sure, informally that's a "method".

Sorry, I don't know what you mean. What in ES5 prevents you from
using which getter or setter syntax? You're right, there's the complex "defineProperty" methode I could use, but they are not so handy.

ES5 standardizes the obj = {get foo() { return 42; }, ...} syntax
already supported by most browsers out there.

Anyway why shouldn't I be able to set private attributes in {}-styled object definitions?

I'm just trying to understand your post. I didn't say anything against
the idea of var in object initialisers, was is proposed for Harmony:

strawman:object_initialiser_extensions, strawman:obj_initialiser_private