我有这两门课:
class Node {
constructor(nodeId){
this.nodeId = nodeId;
this.adjacencies = [];
}
connectToNode(nodeToConnectTo){
this.adjacencies.push(nodeToConnectTo);
}
}
class Graph{
constructor(nodes){
this.nodes = nodes;
}
printGraph(){
for (let node in this.nodes){
console.log(node.nodeId);
}
}
}
我只是想通过这种方式调用printGraph打印所有nodeIds :
let node1 = new Node('1');
let node2 = new Node('2');
let node3 = new Node('3');
const arr = [node1, node2, node3];
let graph = new Graph(arr);
graph.printGraph();
但它正在打印undefined。我似乎无法弄清楚为什么它不简单地打印nodeId.
尚方宝剑之说
炎炎设计
慕哥9229398
蓝山帝景
相关分类