How much sugar do classes need?

Peter Michaux petermichaux at gmail.com
Tue Dec 2 10:54:25 PST 2008


On Mon, Dec 1, 2008 at 12:01 PM, David-Sarah Hopwood
<david.hopwood at industrial-designers.co.uk> wrote:

>  var self = {
>    method toString: {|| '<' + self.getX() + ',' + self.getY() + '>'},
>    method getX: {|| x},
>    method getY: {|| y},
>    field pubInstVar: 4,
>    const pubInstConst: -4,
>  };
>  return self;
>
> where the extensions to the object literal syntax used here are:
>  - a 'field' modifier to declare a property non-[[Configurable]],
>  - a 'const' modifier to declare a property non-[[Configurable]]
>   and non-[[Writable]],
>  - a 'method' modifier to declare a property non-[[Configurable]],
>   non-[[Writable]] and non-[[Enumerable]].

I don't think only a "method" would have the combination of attributes
listed above. Also because functions are first class in JavaScript, I
think of a function valued property as a field so don't like the name
"field". Also would "method" be able to be a lambda or function?

There are 2^3 = 8 combinations of Configurable, Writable, Enumerable
and potentially more attributes in the future. I'd prefer to control
them independently. If multiple prefix modifiers are not appealing,
what about some flags like the 'g' that can follow a regexp literal
(e.g. /a/g)


var self = {
  toString[]: {|| '<' + self.getX() + ',' + self.getY() + '>'},
  getX[]: {|| x},
  getY[]: {|| y},
  pubInstVar[WE]: 4,
  pubInstConst[E]: -4,
};

If no brackets are included then it would be equivalent to [WEC] as
that is backwards compatible (I think).

I'm not sure I like this idea. It is just an idea.

Peter


More information about the Es-discuss mailing list