javascriptにエンティティ/コンポーネントコードがあります。それはほとんど完了しましたが、私はこの本当に奇妙な問題にぶつかっています。私のエンティティには、子をプッシュする子配列があり、そのコンポーネントの他の配列(componentsDictionary、名前は変更されますが、以前はdictでした)があります。
this.childrens.push(obj)を呼び出すと、this.childrens内とobj.childrens内の両方でオブジェクトがプッシュされます...レンダリングツリーを更新するときに無限ループが発生します。
おそらくJSでのクロージャの本当に奇妙な処理の問題です...
問題のあるコードは次のとおりです。
Entity.prototype = {
    childrens : [],
    componentsDictionary : [],
    sharedAttributes : {}, // This data is shared for all components
    debugName : "Entity Default Name",
    bubblee : null,
    Add : function(obj) {
        if (obj instanceof Entity) {
            alert(obj.debugName); // alerts "entity 0"
            alert(this.debugName); // alerts "root"
            alert(obj.childrens.length); // "alerts 0"
            this.childrens.push(obj);
            alert(obj.childrens.length); // "alerts 1"
            // how the f... !%!??!%11?
        }
        else if (obj instanceof IComponent) {
            this.componentsDictionary[obj.type].push(obj);
        }
        else {
            throw new Exceptions.IllegalAction("Attempted to add something else than an entity or a component to an entity.");
        }
    },
どうもありがとう!
ニック