I have the following JS class
class Tree {
constructor(rootNode) {
this._rootNode = rootNode;
rootNode.makeRoot();
}
getRoot() {
return this._rootNode;
}
findNodeWithID(id) {
return this.findNode(this._rootNode, id);
}
findNode = (node, id) => {
if(node.id === id) {
return node;
} else {
node.getChildren().forEach(child => {
this.findNode(child, id);
});
}
return null;
}
}
I have two issues:
This won't compile, gives an error
findNode = (node, id) => { ^ SyntaxError: Unexpected token =
When I change it to a regular function
findNode = (node, id) => {
...
}
the method findNodeWithID doesn't work. Any idea why?