I was wondering if textContent property of an HTML element is a getter that's searching through nodes recursively to find text nodes.
I did an experiment:
Object.defineProperty(HTMLElement.prototype, 'textContentMyOwnImplementation', {
get() {
const result = [];
function search(node) {
if(node.nodeName == '#text')
result.push(node.data);
else
for(let i = 0; i < node.childNodes.length; i++) {
search(node.childNodes[i]);
}
}
search(this);
return result.join(' ');
}
})
The result is the same as textContent's.
This brought me to a question. Is there any way to determine whether a property is an accessor or not?