I am trying to get a recursion method to work in a class context. Within my class I have the following method:
countChildren(n, levelWidth, level) {
The this inside the foreach than the this in the class. In your case, this refers to the current element being iterated.
you need to bind the scope.
n.children.forEach(function (n) { this.countChildren(n, levelWidth, level+1); }.bind(this));