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

Boris Zbarsky bzbarsky at MIT.EDU
Fri Nov 30 13:31:12 PST 2012


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?

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...

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.

> 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?

-Boris




More information about the whatwg mailing list