Quite verbose, harder to optimize and only supports string keys. On Wednesday, 28 October 2015, Jordan Harband <[email protected]> wrote:
> fwiw, my Object.entries proposal ( > https://github.com/ljharb/proposal-object-values-entries ) would allow > you to do: `new Map(Object.entries({ a: 'b', b: 'c' }))`. > > On Tue, Oct 27, 2015 at 4:36 PM, Alexander Jones <[email protected] > <javascript:_e(%7B%7D,'cvml','[email protected]');>> wrote: > >> I agree this is pretty important. Using actual maps really frees up a lot >> of complexity, but the syntax is cumbersome to say the least. >> >> Whatever the decided syntax, bare words as string keys is a really bad >> idea IMO. The key syntax should be parsed as an expression, like the values >> are, and like they are in basically every other language. >> >> Another outstanding issue is that we might want the syntax for >> `Immutable.Map`, or `WeakMap`, or `MapTwoPointOh` that improves deficiency >> $x, $y and $z. I'd say introducing a special syntax for `Map` right now is >> not ideal. >> >> Rather, we have an opportunity to instead devise a syntax for an abstract >> map. While we're at it, we might as well do the same for an abstract list. >> Why should maps have all the fun? >> >> ``` >> const {List: IList, Map: IMap} = Immutable; >> const bar = 43; >> const map = IMap#{"foo": 42, bar: 44}; // keys "foo" and 43 >> const list = IList#[4, 5, 6, 7, Map#{map: "why not?"}]; // 5th element >> is a Map with one key, which is the Immutable.Map above >> const weakMap = WeakMap#{map: "It's an Immutable", list: "Also >> Immutable"}; // WeakMap keys are the objects map and list >> ``` >> >> It could desugar as, for the sake of example: >> >> ``` >> Foo#{key: value, ...} >> ➔ >> Foo[Symbol.literalOf]([[key, value], ...][Symbol.iterator]()) >> ``` >> >> and >> >> ``` >> Foo#[value, ...] >> ➔ >> Foo[Symbol.literalOf]([value, ...][Symbol.iterator]()) >> ``` >> >> The nice thing about this is it's extensible and future proofs the >> language a little bit. The actual arrays need not exist if engines choose >> to implement this more efficiently - the syntax just results in an iterator >> which yields the elements of the literal. The only difference between the >> `[]` and the `{}` notation ise that the `{}` notation enforces >> syntactically valid key-value pairs and are a little less heavy on brackets. >> >> I know literally every proposal ever these days seems to claim the `#` >> symbol now, so that's clearly an issue to contend with... :) >> >> Alex >> >> >> On 27 October 2015 at 22:55, Mohsen Azimi <[email protected] >> <javascript:_e(%7B%7D,'cvml','[email protected]');>> wrote: >> >>> I'm using Maps a lot now and I was thinking why there is no "easy" way >>> of declaring them like objects and arrays. >>> >>> I'm sure I'm not the first one who came up with the idea of having Map >>> literal declaration. There are many ways we can introduce new syntax for >>> declaring Maps via a literal syntax such as: >>> >>> ``` >>> let map = [window: 'window', document: 'document']; >>> ``` >>> or >>> ``` >>> let map = {{window: 'window', document: 'document'}} >>> ``` >>> and possibly many more. >>> >>> I searched the discussions but couldn't find a topic on this. Have you >>> discussed this before? >>> >>> _______________________________________________ >>> es-discuss mailing list >>> [email protected] >>> <javascript:_e(%7B%7D,'cvml','[email protected]');> >>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> >> >> _______________________________________________ >> es-discuss mailing list >> [email protected] >> <javascript:_e(%7B%7D,'cvml','[email protected]');> >> https://mail.mozilla.org/listinfo/es-discuss >> >> >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

