I would create a NodeList object, that puts the logic of getNodeList into its constructor. It would be an iterable object.