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) {
Try using .call()
to invoke the function. That way you can specify the context directly.
Like this:
this.countChildren.call(this, n, levelWid);
th, level+1
Edit: Noticed my error, what you should really do is bind the anonymous function:
like this:
n.children.forEach(function (n) {
this.countChildren(n, levelWidth, level+1);
}.bind(this));