The hierarchical structure of the Yui Dom module is clear:
Expanded detail: yui-dom-full.png
Some experiences
- The submodules organization mode is very clear. The division of labor between submodules is clear, and the source code is as clear as haoyue.
- Selector-css3 uses the plugin method, reserved in the selector-css2 Extended Interface, css3 directly expand pseudo class and operator. This extensible writing method is also used multiple times in detailed code, such as writing some compatible code for IE. The code is independent and can be added and cut, very cute.
- Flexibility of small particles is also costly. Some code may be duplicated between submodules. The value is not worth mentioning.
- The ternary operator is a good thing:
getText: (document.documentElement.textContent !== undefined) ?
function(element) {
var ret = '';
if (element) {
ret = element.textContent;
}
return ret || '';
} : function(element) {
var ret = '';
if (element) {
ret = element.innerText;
}
return ret || '';
}
In different browsers, gettext points to different functions, and the judgment in the ternary operator only needs to be executed once.
There is also a way to write:
_childrenByTag: function() {
if (document[DOCUMENT_ELEMENT].children) {
return function(element, tag, fn, toArray) {
...
};
} else {
return function(element, tag, fn) {
...
};
}
}()
The function that returns the function is quite useful.
- Before reading the source code, I will try to answer a question: how can I design the DOM API and draw a picture? Finally, the API and
In contrast to yui3, in my design, the functions are comprehensive, but in terms of hierarchical classification and definition, yui3 is much better. In general, comparing and learning API design has a fascinating world.
- I did not go into the code details this time. I keep reminding myself to look at the overall situation. If you are willing to give it up, you can get it.