Commit b87e1395 authored by Robert Knight's avatar Robert Knight

Rewrite a comment

Try to explain the issue with `textContent` in a better way.
parent dd0af4d8
/** /**
* Return the combined length of text nodes contained in `node`. * Return the combined length of text nodes contained in `node`.
* *
* This is different than `node.textContent` if called on a comment or processing
* instruction directly.
*
* @param {Node} node * @param {Node} node
*/ */
function nodeTextLength(node) { function nodeTextLength(node) {
switch (node.nodeType) { switch (node.nodeType) {
case Node.ELEMENT_NODE: case Node.ELEMENT_NODE:
case Node.TEXT_NODE: case Node.TEXT_NODE:
// nb. `textContent` excludes text in comments and processing instructions
// when called on a parent element, so we don't need to subtract that here.
return /** @type {string} */ (node.textContent).length; return /** @type {string} */ (node.textContent).length;
default: default:
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment