Я пытаюсь создать древовидную структуру в javascript.Вот класс узлов:
class NodeTree {
constructor(parent, chkAttacked, chkType, coords) {
var children;
this.parent = parent;
this.chkAttacked = chkAttacked;
this.chkType = chkType;
this.coords = coords;
}
setChild(node) {
children.push(node);
}
getCoords() {
return coords;
}
getParent() {
return parent;
}
getChildren() {
return children;
}
getChkAttacked() {
return chkAttacked;
}
getChkType() {
return chkType;
}
}
Дочерние узлы не объявляются одновременно с созданием объекта и по этой причине устанавливаются позже.В таком виде я получаю «не определенную ошибку».Как установить дочерние узлы вне конструктора?