How much sugar do classes need?

Peter Michaux petermichaux at gmail.com
Tue Dec 2 13:58:27 PST 2008


On Tue, Dec 2, 2008 at 1:40 PM, Jon Zeppieri <jaz at bu.edu> wrote:

> #{ ... } is an object initializer where all of the initialized
> properties are non-configurable.

The use of '#' makes me think of reader macros. I like the idea of
reader macros for ES. (I don't know if '#' can be used because of
sharp variables which I believe are part of JavaScript.)

I think it would be good to be able to use custom quotes on regular
expressions and strings

#r(some/regexp/containing/slashes)

#s/a string containing " quotation ' marks/


> 'enum' (or something similar) is a property modifier that makes the
> property enumerable.
> 'const' continues to have the same meaning (non-configurable and
> non-enumerable).  Where 'const' appears inside #{ ... }, the
> non-configurable aspect is redundant.
>
> var self = #{
>  const toString: {|| '<' + self.getX() + ',' + self.getY() + '>'},
>  const getX: {|| x},
>  const getY: {|| y},
>  enum pubInstVar: 4,
>  enum const pubInstConst: -4
> };
>
> It's more verbose than Peter's syntax, but it doesn't overload the
> array index syntax,

I used [] just as an example. It could have been many different separators.

> and although the #{ ... } initializer
> unfortunately introduces new syntax, I think its functionality is
> genuinely (and generally) useful.  I'd imagine that most real-world
> uses of { ... } could be replaced by #{ ... }, since initialized
> properties are usually expected to stick around.
>
> On the other hand:
>
>  enum const get foo () { ... }
>
> ... is odd.

I think if there are to be modifiers than just have the modifiers and
not the #{}. Having all the modifiers with the property seems like a
better way to go to me. Also what if #{} is used to create the object
and later a property is added and is to be configurable? Is that
possible? Either decision seems arbitrary.

If there are going to be modifiers "config", "enum", and "const" then
there may be no harm in having other modifiers which represent a
combination of these modifiers (like the suggestions of "field" and
"method" though I don't really like those names for the reasons I
wrote before.)

Peter


More information about the Es-discuss mailing list