Non-generic traps for non-generic objects (was: Overriding Map/etc with get/set hooks?)
Tab Atkins Jr.
jackalmage at gmail.com
Fri May 24 10:47:13 PDT 2013
On Fri, May 24, 2013 at 10:11 AM, Andreas Rossberg <rossberg at google.com> wrote:
> On 24 May 2013 18:55, Tab Atkins Jr. <jackalmage at gmail.com> wrote:
>> impossible, forcing all Maps to be any->any, and offering only hacks
>> (admittedly clever ones) that partially work if you want a restricted
> I haven't really followed this thread, but could it be that you are
> confusing polymorphic instantiation with subtyping here? A Map(String,
> String) is an instance of a polymorphic Map(A, B), but it is not a
> subtype of Map(Any, Any), because a map is contravariant in its key
> type. That's why the subclassing you have in mind does not really make
> sense from a subtyping perspective. If you want to restrict it, then
> you'd have to do so by wrapping, not by inheritance.
This is a reasonable argument, but there's no other way to express the
right semantics in JS (this is a map, operations you add to general
maps apply to this as well) without subtyping. If we ever come up
with better solutions to handling OO, great, but I'm unhappy if we
block any attempt to address Web API map-like needs just because it's
not *technically* a subclass.
More information about the es-discuss