Re: [whatwg] [URL] DOM API Feedback

On Sun, Nov 18, 2012 at 3:17 PM, Anne van Kesteren <annevk@annevk.nl> wrote:
> On Sun, Nov 18, 2012 at 11:34 PM, David Bruant <bruant.d@gmail.com> wrote:
>> I feel the URLQuery object could be a regular object. Or maybe an ES6 Map.
>> If not an ES6 Map, maybe its API could be mapped exactly to ES6 Map. It
>> would increase interoperability.
>
> It cannot be a regular object because it modifies an underlying
> string. I suppose the same goes for ES6 Map. And URLQuery represents
> an ordered list of key-value pairs so I'm not sure how close it can
> be.

URLQuery is already *almost* duck-typed as a Map.  It's only missing:
* the has() function (strictly unnecessary given the restriction that
values are all strings, but nearly free, and useful for API
consistency)
* the iteration functions keys(), values(), and items().

It would be nice if, as previously mentioned, you could do a bulk-set.
 Just use the same meaning as the Map constructor, where it takes any
iterable, converts the keys and values to strings, and goes through it
in iteration order, adding each pair.

Even though it has magic behavior underneath, I think it should still
be possible to be a subclass of Map, which would be the best thing.
Then, the missing parts I described above would come for free.

~TJ

Received on Sunday, 18 November 2012 23:54:08 UTC