I'm trying to work through to understand Crockford's walk_the_dom
function below. Here is my logic and the DOM tree I am working with. I don't see when node.nextSibling
is reached.
function walk(node, func) {
func(node);
node = node.firstChild;
while (node) {
walk(node, func);
node = node.nextSibling;
}
};
func(node) runs a function on #text
node = node.firstChild() --> what is the firstChild of #text ?
The firstChild
of #text is null
or undefined
because there isn't any. JavaScript has what is known as truthy
values. So while(null)
is the same as while(false)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.