Classes: Moving away from object literal syntax

Axel Rauschmayer axel at rauschma.de
Wed Mar 21 10:25:30 PDT 2012


On Mar 21, 2012, at 12:42 , Herby Vojčík wrote:

> Yeah, they are pushing it hardly this way. It seems inevitable...
> I am willing to accept it, but I'd like to have a clear mapping from object initializer components into class body components - if it is there, I don't care about syntax (the main concern for me is, that if certain things are possible in object initializer, they should be either:
> - known to be banned in class, or
> - straightforwardly mappable
> 
> That brings the question: what about static block? I think it should have exactly same rules as the basic class block (sans possibility having its own nested static block). That is, what about that const? Is data allowed in static (const-only or let as well) but not in class; or is it possible in class as well (which means, it defines shared data thing in prototype)?

“I think it should have exactly same rules as the basic class block” – I agree 100%.

Const is indeed tricky – I always liked the # sigil proposal for object literals, but I don’t think they can work with this syntax. Const only means non-writable and makes just as much sense for methods. Shared data (as in “properties whose values are not functions”) should not be allowed for the prototype, because it makes no sense.

> Axel Rauschmayer wrote:
>> Brendan argued that if you restrict in class declarations what you can do syntactically then basing their syntax on object literals will confuse people. I agree. Based on that and on a recent proposal for a non-braces private syntax, I’ve updated my class declaration proposal:
>> 
>> https://gist.github.com/1336846

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120321/fce8e498/attachment.html>


More information about the es-discuss mailing list