3 ms·
I'm going to propose one of my own[1], since I can do few projects without time limit (for fun) so I did my best to properly program, test and document it. I ov
by franciscop 11y ago
I'm going to propose one of my own[1], since I can do few projects without time limit (for fun) so I did my best to properly program, test and document it. I overcommented on the past but I'm trying to correct it now. Also, all of the new contributors follow the same style so things stay consistent. As an example, let's try to understand the function `.addClass`:
- Just to use it you can see the documentation on the website[2], which is the first contact normally.
- Then when you try to find the relevant files. They are in github's `src/plugins/addclass`, a name that is common and intuitive [3].
- Not only that, but you also got the documentation in that folder in github thanks to the name `readme.md`.
- When opening it [4], the first thing that you note is that the function has a tiny footprint; 8 lines. A brief explanation of what it does and a line explaining what the not-so-intuitive function `this.eacharg()` means.
- Then we use the native `Element.classList` [5] to add classes. Most people familiar with vanilla javascript know it, but otherwise the name is quite descriptive `el.classList.add(name)`
In contrast, while covering quite few other edge cases and older browsers, check jQuery's `.addClass()` code [6]. Or check Zepto.js' `addClass()` code [7]
[1] http://github.com/umbrellajs/umbrella/ http://github.com/umbrellajs/umbrella/
[2] http://umbrellajs.com/documentation#addclass http://umbrellajs.com/documentation#addclass
[3] https://github.com/umbrellajs/umbrella/tree/master/src/plugins/addclass https://github.com/umbrellajs/umbrella/tree/master/src/plugi...
[4] https://github.com/umbrellajs/umbrella/blob/master/src/plugins/addclass/addclass.js https://github.com/umbrellajs/umbrella/blob/master/src/plugi...
[5] https://developer.mozilla.org/en/docs/Web/API/Element/classList https://developer.mozilla.org/en/docs/Web/API/Element/classL...
[6] https://github.com/jquery/jquery/blob/305f193aa57014dc7d8fa0739a3fefd47166cd44/src/attributes/classes.js#L17 https://github.com/jquery/jquery/blob/305f193aa57014dc7d8fa0...
[7] https://github.com/madrobby/zepto/blob/601372ac4e3f98d502c707bf841589fbc48a3a7d/src/zepto.js#L732 https://github.com/madrobby/zepto/blob/601372ac4e3f98d502c70...