[whatwg] Make DOMStringMap constructable, and el.dataset writeable?

Tab Atkins Jr. jackalmage at gmail.com
Fri Nov 30 16:07:09 PST 2012

On Fri, Nov 30, 2012 at 1:31 PM, Boris Zbarsky <bzbarsky at mit.edu> wrote:
> On 11/30/12 2:23 PM, Tab Atkins Jr. wrote:
>> It would be somewhat cleaner if she could simply construct a
>> DOMStringMap and assign it, like so:
>> for(var i = 0; i < cards.length; i++) {
>>    cards[i].dataset = new DOMStringMap(carddata[i]);
> So this would copy the DOMStringMap into the dataset, not actually change
> the value of cards[i].dataset, right?

Sure.  I presume you're afraid of multiple elements sharing the same object?

> Given that, would it make more sense to just have a setFrom method on
> dataset that takes a string?  I guess the problem with that is name
> collisions with data items...

Yes, collisions make this a no-go.

> Really, what we want to be able to do here is assign a string to .dataset
> and have it do the right thing...  WebIDL doesn't really support that very
> well; perhaps it should.

What would the string be?  String-serialized JSON object?

Isn't this what [PutForwards] is for?

>> Another potentially interesting use-case for this is making it
>> possible to "transfer" data-* attributes from one element to another
>> with a simple "el1.dataset = el2.dataset;" statement.
> Again, this would copy, not share, yes?

Yes.  I presume same fear?


More information about the whatwg mailing list