Setting up (non-index) properties of arrays

Axel Rauschmayer axel at rauschma.de
Sat Aug 4 16:19:29 PDT 2012


> Separately, we've long entertained extending array literals to encompas ad-hoc properties (expandos). Also the dict strawman wants [a:1,b:2] syntax. I think expandos on arrays are rare enough that dicts should win, if it comes down to a future-proofing fight.

Agreed on rareness. If dicts are only maps from string to value [1] (a safe object-as-map, if you will) then I don’t think we need a literal/initializer syntax for that – they can easily be initialized via object literals, e.g.:
dict({ a: 1, b: 2 })

However, [a:1,b:2] or {| a: 1, b: 2 |} would be great as a literal syntax for maps (from value to value). That is, `a` and `b` would be identifiers and not string keys. But that must make parsing difficult. Even something very restrictive (such as: parens if there is more than one token in the expression) does not seem much help.


[1] http://wiki.ecmascript.org/doku.php?id=strawman:dicts

> 
> /be
> 
> Axel Rauschmayer wrote:
>> As an example, a template string call site ID would be constructed as follows:
>> 
>>    const callSiteId1234 = do {
>>        let literalParts = ['lit1\n', ' lit2 ', ''];
>>        literalParts.raw = ['lit1\\n', ' lit2 ', ''];
>>        literalParts
>>    };
>> 
>> How about the following abbreviation?
>> 
>>    const callSiteId1234 = ['lit1\n', ' lit2 ', '', raw: ['lit1\\n', ' lit2 ', '']];
>> 
>> Not sure it’s a frequent-enough use case, though. Mustache would be nice here, or one could use Underscore:
>> 
>>    const callSiteId1234 = _.extend(['lit1\n', ' lit2 ', ''], {raw: ['lit1\\n', ' lit2 ', '']});

-- 
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/20120805/6f565242/attachment-0001.html>


More information about the es-discuss mailing list