Deprecating objects as maps from strings to values?

# Axel Rauschmayer (14 years ago)

harmony:simple_maps_and_sets

Will simple maps replace objects in their capacity to map from strings to values?

  • That would obviate the need for many "own" trickeries (to avoid finding an inherited property name).
  • But: we would need a map literal. Or at least a way to construct maps via method chaining.

Obviously, mapping from non-strings to values is useful in its own right.

# Brendan Eich (14 years ago)

On Oct 2, 2011, at 4:24 PM, Axel Rauschmayer wrote:

harmony:simple_maps_and_sets

Will simple maps replace objects in their capacity to map from strings to values?

  • That would obviate the need for many "own" trickeries (to avoid finding an inherited property name).
  • But: we would need a map literal. Or at least a way to construct maps via method chaining.

strawman:dicts

Obviously, mapping from non-strings to values is useful in its own right.

And a good way to leak.

# Axel Rauschmayer (14 years ago)

Obviously, mapping from non-strings to values is useful in its own right.

And a good way to leak.

This almost sounds like something desirable. ;-)

I do realize that this results in a lot of follow-up work (defining equality for objects etc.). But every now and then, I define immutable objects (e.g. points, units, etc.) and would like to put them in a set or a map. Python and Java can do it, why can’t ES.next?

# Brendan Eich (14 years ago)

On Oct 2, 2011, at 4:58 PM, Axel Rauschmayer wrote:

Obviously, mapping from non-strings to values is useful in its own right.

And a good way to leak.

This almost sounds like something desirable. ;-)

I do realize that this results in a lot of follow-up work (defining equality for objects etc.). But every now and then, I define immutable objects (e.g. points, units, etc.) and would like to put them in a set or a map. Python and Java can do it, why can’t ES.next?

You and others can write such maps, imposing some equivalence relation on objects using your own conventions instead of ===, using ES.next maps (weak or strong). If it's only "every now and then", it would be better if the ecosystem solves this through design and competition for reuse via github, etc. No premature design and standardization of something not widely needed or in use already.

# Axel Rauschmayer (14 years ago)

Excellent point – easily added via a library! That’s the way to go.

One of JSWG’s roles could be to provide tools/processes to help the library community find common ground in such matters. My impression is that there are currently too many reinvented wheels in JS. But I might be wrong: E.g. CommonJS seems to do a lot of good work and maybe is already playing the previously mentioned role.