On Wed, Oct 8, 2014 at 3:09 PM, Brendan Eich <bren...@mozilla.org> wrote:
> Dmitry Soshnikov wrote: > >> >> The Collection protocol thus consists of at least .constructor, >> @@iterator, .set. (Is there a better way to clone? Don't want a >> new protocol where an old one will suffice!) This Collection >> protocol would include Map and maplikes but leaves out Set, Array, >> Object -- appropriately. >> >> >> As long as it can be generic enough for `Map`, `Set` >> > > Set methods include add, whereas Map has set. Set lacks a get method, > whereas Map of course has one. So not the same protocol. > > I see, yeah, it's doable, and potentially they can be handled via abstract operations with checking kind of a collection (`IsSet`, `IsMap`), and setting needed entries (`AddEntry` would cover `set` for maps, and `add` for Sets), and `GetEntry` would return needed thing since sets are just backed by maps. However, this seems not a big win in terms of constant runtime checks for this, and probably having a separate algorithms are better (even if some parts are repeated). If you want to have just an explicit protocol/interface for "MapLike"s and "SetLikes" (i.e. with any explicit `set` method, and stuff which can be implemented at user-level by any object), it's possible. Although, this interface implementation can also be just replaced with sub-classing of the `Map`, and the same algorithm works. It's just a difference b/w duck-typing (the protocol, that any object may implement regardless its hierarchy), or the inheritance. Will think about it, and maybe will come up with a spec. Dmitry
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss