Array.prototype.unshift.apply(this.nodes, getChildren(currentNode))

I would pass nodesToVisit to getChilden (to not create a new array) and push items directly to the nodesToVisit (shift operation might be replaced with pop)