Wednesday, January 2, 2013

dojo/dom-class vs. native classList

1) html 5 supports classList
http://davidwalsh.name/classlist

2) dojo implementation is not using these native methods, and is slow compared to native variants:
http://jsperf.com/native-dojo-class-manipulation-v-html5/7

Here is (my) draft of improvement: 
http://jsperf.com/native-dojo-class-manipulation-v-html5/8
(last method "Has Class - Dojo - with feature detection" and naive has(), contains1() methods)

Native support detection issue is also mentioned in bug discussions (currently closed as 'rejected'):
http://bugs.dojotoolkit.org/ticket/11465

More, it is marked as "posterity" in latest source code (line 43):

https://github.com/dojo/dojo/blob/master/dom-class.js



3) Many HTML5 support detections are still missing in has.js: 

IMHO, about classList, only pull request from brianforbes, 2 years old (quite ugly):
https://github.com/bryanforbes/has.js/commit/c2711e28989c0b838ea5d121915de3dad6952b0b

 
For the beginning, we are comparing:
Has Class - Dojo
domClass.contains("single_class", "a_class");
Has Class - HTML5
document.getElementById("single_class").classList.contains("a_class");
classList contains with dojo byId
dom.byId("single_class").classList.contains("a_class");
Has Class - Dojo - with feature detection
domClass.contains1("single_class", "a_class");

http://jsperf.com/native-dojo-class-manipulation-v-html5/8

No comments:

Post a Comment