function fds (node, set = new Set()) {
let tagName = '';
//
if (node.nodeType === 1) {
tagName = node.tagName;
set.add(tagName);
}
const children = node.childNodes;
const len = children.length;
for (let i = 0; i < len; i++) {
fds(children[i], set);
}
return [...set];
}
fds(document);
递归方式实现: