lib/utils/DOMPostOrder.js
function DOMPostOrder(root, visitFunc) {
	let node = root;
	while (true) {
		// Find leftmost (grand)child, and visit that first.
		while (node.firstChild) {
			node = node.firstChild;
		}
		visitFunc(node);
		while (true) {
			if (node === root) {
				return; // Visiting the root is the last thing we do.
			}
			/* Look for right sibling to continue traversal. */
			if (node.nextSibling) {
				node = node.nextSibling;
				/* Loop back and visit its leftmost (grand)child first. */
				break;
			}
			/* Visit parent only after we've run out of right siblings. */
			node = node.parentNode;
			visitFunc(node);
		}
	}
}
function DOMPostOrder(root, visitFunc) {
	let node = root;
	while (true) {
		// Find leftmost (grand)child, and visit that first.
		while (node.firstChild) {
			node = node.firstChild;
		}
		visitFunc(node);
		while (true) {
			if (node === root) {
				return; // Visiting the root is the last thing we do.
			}
			/* Look for right sibling to continue traversal. */
			if (node.nextSibling) {
				node = node.nextSibling;
				/* Loop back and visit its leftmost (grand)child first. */
				break;
			}
			/* Visit parent only after we've run out of right siblings. */
			node = node.parentNode;
			visitFunc(node);
		}
	}
}
function DOMPostOrder ( root , visitFunc ) { let node = root ; while ( true ) { // Find leftmost (grand)child, and visit that first. while ( node . firstChild ) { node = node . firstChild ; } visitFunc ( node ) ; while ( true ) { if ( node === root ) { return ; // Visiting the root is the last thing we do. } /* Look for right sibling to continue traversal. */ if ( node . nextSibling ) { node = node . nextSibling ; /* Loop back and visit its leftmost (grand)child first. */ break ; } /* Visit parent only after we've run out of right siblings. */ node = node . parentNode ; visitFunc ( node ) ; } } }
Non-recursive post-order traversal of a DOM tree.
@param {Node} root
@param {Function} visitFunc Called in post-order on each node.
Non - recursive post - order traversal of a DOM tree .