javascript - 懒类参数设置
问题描述
我正在尝试在 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;
}
}
子节点不会在创建对象的同时被声明,因此稍后设置。就目前而言,我得到一个“未定义的错误”。如何在构造函数之外设置子节点?
解决方案
推荐阅读
- java - 如何使用 JAVA 从 Azure 的 Cosmos DB 集合中获取所有文档?
- erlang - 如何在 shell 中使用 rebar3 创建 Erlang 应用程序?
- ios - c文件可以读取Xcode中的本地化字符串吗?
- java - 如何根据系统环境属性更改枚举值
- windows - 在 Windows 机器上构建 docker 映像时出现 chmod CommandNotFoundException
- c - CC1352P 启动板 SPI 接口不适用于我的应用
- php - 如何使用按日期范围的动态 mysql 查询从数据库中获取数据
- c# - 如何诊断 .net core ANCM 进程内启动失败
- browser - 如何更改 JMeter 执行目标浏览器?
- php - 如何在日期选择器中设置动态选定月份的第一个日期?