[Bug 17708] DOMTokenList: Ability to swap a class

https://www.w3.org/Bugs/Public/show_bug.cgi?id=17708

Glenn Maynard <glenn@zewt.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |glenn@zewt.org

--- Comment #1 from Glenn Maynard <glenn@zewt.org> 2012-07-06 23:07:19 UTC ---
(In reply to comment #0)
> $("article").removeClass("closed").addClass("opened");
> 
> If developers are going to swap CSS classes around in the method above, then
> they might as well have an efficient means to do that. 

What do you mean by "efficient"?  I doubt there's any performance issue here. 
If you mean "less typing", this is already pretty concise (even without the
chaining shortcut).

> Or other similar code. We also saw evidence that developers assume that class
> lists retain order:
> 
> if(elem.classList === "x y") {
>    .... 
> } 
> 
> This could lead to confusion when using DOMTokenList toggle(), as toggle
> destroys the ordering of CSS class list names of an attribute.  
> 
> Given the above, I'll like to request we add swap() method to DOMTokenList().
> It would swap one token for another while retaining item order.

This seems to be increasing the surface area of the API just to make it easier
to get bad practices to work.  It encourages people to write more code that
depends on the order of the class list--which should be discouraged--instead of
fixing the real problem (use classList.contains(), not string comparison).

-- 
Configure bugmail: https://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Friday, 6 July 2012 23:07:20 UTC