2.3.2. DOMTokenList

(This is part of my detailed review of the Document Object Model section.)

1. I suggest DOMTokenList methods add() and remove() return
DOMTokenList itself. This would allow for useful function chaining,
f.e.:

   myDiv.classList.add('toFront').toggle('maximized');

Consider that jQuery already uses similiar approach. I'm not sure if
this would be useful on other objects which use DOMTokenList interface
but certainly it is for classList. I'd even consider such behavior for
toggle() but I don't have strong opinion about that.

2. Anyway, I know that this was discussed on WHATWG list but why not
extend className instead of adding classList? Is this producing some
serious compatibility problems? As I understand current spec classList
stringify to the same value as className.


3. I'm not sure if it is intended but with current algorithms for
adding token in add() and toggle() methods when DOMTokenList object's
underlying string is  empty it ends up with value of  U+0020 SPACE +
token. Shouldn't there be condition that if underlying string is empty
then append only token? I believe that today's common way of obtaining
classList is via:

   classArray = myDiv.classList.split(' ');

With current algorithm it will lead to array with additional empty
elemets and could cause some compatibility problems with existing
pages.

-- 
Best regards,
Marek Paw這wski

Received on Wednesday, 5 September 2007 13:01:46 UTC