[Bug 17708] DOMTokenList: Ability to swap a class

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

--- Comment #3 from Glenn Maynard <glenn@zewt.org> 2012-07-07 17:06:31 UTC ---
(In reply to comment #2)
> There is potentially a significant performance gain. Check this out: 
> http://youtu.be/hZJacl2VkKo 

Do you have a simple benchmark?  I don't really want to watch a video.

And, more importantly, why can't this be optimized by browsers without adding
API?  I'd expect modern browsers to apply the effects of classes lazily, so
making multiple changes is roughly free.  That's similar to how changing DOM
properties usually doesn't trigger layout immediately, so making lots of
changes to an object isn't expensive.  Does something make classes a harder
problem than that?

FWIW, I rarely actually swap classes like this.  Toggling a class and using
:not(.class) usually works well, and tends to give simpler code, too.

> To do the queries that you suggest is more annoying. You would need to do the
> following:
> 
> if(elem.classList.contains("x") && elem.classList.contains("y"))
> 
> When what you really want is:
> if(elem.classList.contains("x", "y", "z")); 
> 
> or 
> (elem.classList.contains(["x", "y", "z"]))
> 
> Getting off topic.

Sure, adding features that encourage not depending on class order is probably a
good thing.  I'm just saying that adding features that do the opposite seems
like a bad approach--it's just giving people workarounds so they can continue
doing things in brittle ways.  (This is orthogonal to performance, of course.)

-- 
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 Saturday, 7 July 2012 17:06:33 UTC