다음 코드는 Mike Bostock의 Force-Directed Graph with Mouseover에서 가져온 것입니다. 나는이 코드에 대해 좀 더 지적한 질문을 할 수 없다는 점을 유감스럽게 생각하지만 누군가가 링크에서 다른 노드를 계산하는 forEach 블록의 구문을 설명 할 수 있는지 궁금합니다.JavaScript의 다중 할당 표현식 및 구문 설명
아래 줄에서 정확히 무슨 일이 일어나고 있으며 어떤 변수에 할당되고 있습니까? 동일한 표현식에 여러 개의 과제를 수행 할 수있는 이름이 있습니까?
link.source = nodes[link.source] || (nodes[link.source] = {name: link.source});
var links = [
{source: "Ericsson", target: "ZTE", type: "suit"},
{source: "Kodak", target: "Samsung", type: "resolved"},
{source: "Apple", target: "Samsung", type: "suit"},
{source: "Kodak", target: "RIM", type: "suit"},
{source: "Nokia", target: "Qualcomm", type: "suit"}
];
var nodes = {};
// Compute the distinct nodes from the links.
links.forEach(function(link) {
link.source = nodes[link.source] || (nodes[link.source] = {name: link.source});
link.target = nodes[link.target] || (nodes[link.target] = {name: link.target});
});