Closed dszlachta closed 8 years ago
Is there a fallback we can use for IE8?
Unfortunately, defining anything similar to getter is impossible in IE8. But we could manipulate Node.childNodes.length after every append/remove. That's not so bullet-proof, but IE8 compatible. I have it here: https://github.com/dszlachta/simple-dom/tree/childNode-length-ie8
@dszlachta WebCore starts maintaining the length on add/remove lazily when you access childNodes.length but like I said, childNodes is still an array like 'view' of the DOM graph, it is not naturally an array, and I'm very tempted to remove childNodes altogether, and replace with hooks for people who want to add support for it or move it to another build.
I would accept a PR that cached and maintained childNodes.length on mutations.
I would accept a PR that cached and maintained childNodes.length on mutations.
Will gladly reopen, if @krisselden feedback is addressed.
In the current master, Node.childNodes has no length property. That's not compliant with DOM Core (http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-203510337) and can be a pain if writing code to check for element children. For example, this simple code won't work:
Using Object.defineGetter seems the simplest and most elegant solution here. It's supported by Chrome, FF, Opera 9.5, Safari 3 and IE 9: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get
Cheers, Dawid