次のオブジェクトがあるとします。
Parent = (function() {
function Parent(child) {
this.child = child;
}
return Parent;
})();
Child = (function() {
function Child(name, parent) {
this.name = name;
this.parent = parent;
}
return Child;
})();
1つのステートメントで親と子を作成する方法はありますか?(子が親を適切に参照している場合)
このようなもの:
var parent = new Parent(new Child("john", thisThatPointsToTheNewParent));
これは私が何を求めているかを示すためだけのものです。子と親を別々に作成し、後で子の参照を更新できることはわかっていますが、私の場合は、一度に実行できればはるかに簡単です。方法はありますか?