So I started cranking out my own framework... I started changing the prototype of
NodeList (which is the return type of the document.querySelectorAll method) and things were going great, until I had to create a NodeList object. new NodeList throws an error...I figured I could get around this problem by extending
NodeList. I did this with the following code:
var ElementList = function() {}
ElementList.prototype = document.querySelectorAll('doesntexist')
This works but it has two problems:
- as you add to the
ElementListarray, the length property doesn't get updated - FF has a bug
(new ElementList) instanceof NodeList == false
/^\d+$/. Then to get around the second one, I might file a bug report to FF, but in the mean time, I just check for ElementList inheritance along with NodeList inheritance. UPDATE
I have since filed a bug with FF, and the issue has been fixed.

Interesting. The oddest thing being that NodeList is not a constructor - even if you try "new nodeListSample.constructor()"...
ReplyDelete