ded / bonzo

library agnostic, extensible DOM utility
Other
1.32k stars 137 forks source link

Use classList if the browser support it #56

Closed Calvein closed 12 years ago

Calvein commented 12 years ago

It's way faster : http://jsperf.com/classlist-vs-bonzo

I first pull request to the brand new vanilla-masonry repo by David DeSandro (https://github.com/desandro/vanilla-masonry/pull/3)

ded commented 12 years ago

pre-define the methods on load rather than each run-time operation, then we got a pull request.

eg:

var hasClass = features.classList ? function (el, c) {
  return el.classList.contains(c)
} : function (el, c) {
  return classReg(c).test(el.className)
}
Calvein commented 12 years ago

Done (I'll add this to masonry too).

ded commented 12 years ago

why do you suppose i got something like this from that test page? perf

jots commented 12 years ago

Hey guys, what do you think about this implementation:

http://jsperf.com/class-stuff

idea from: https://github.com/rightjs/rightjs-core/blob/master/src/dom/element/styles.js

Calvein commented 12 years ago

@ded ClassList is a bit slower than the RegExp on Chrome 15 but a bit faster on Chrome 16/17, in 2 weeks nobody will use Chrome 15 anymore. And it's way faster on Firefox/Opera.

@jots That's nice but it looks like classList will be faster on Firefox/Opera, we may let the classList, it's up to @ded.