0

Object.observe()からの再帰的な変更を監視するために数か月前に使用していましたwindow.document。現在、Oo() は em6+ から廃止されているため、この動作をカスタマイズする必要があります。ドキュメント内の任意の場所に作成された新しい要素にアクセスする必要があります。

私はこれらのプロジェクトを試しました(動作しますが、子の再帰はありません):

https://github.com/MaxArt2501/object-observe

https://github.com/jdarling/Object.observe

https://github.com/jdarling/Object.observe

Mozilla MDN からproxy https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxyを使用するように読みましたが、どのトラップを使用すればよいか、またはこれを再帰的にする方法がわかりません。

Oo() で使用している正確なコードは次のとおりです。

                    var observer = new MutationObserver(function (mutations) {
                        mutations.forEach(function (mutation) {
                                console.log("Observed Mutation:");
                                //mutation.target
                                //mutation.type
                                //mutation.oldValue
                                //mutation.attributeName
                                //mutation.attributeNamespace
                                //mutation.removedNodes
                                //mutation.addedNodes
                        });
                    });

                    //mutation observer configuration
                    var config = {
                        childList: true,
                        attributes: true,
                        characterData: true,
                        subtree: true,
                        attributeOldValue: true,
                        characterDataOldValue: true
                        attributeFilter: false
                    };

                    // pass in the target node and options to mutation observer
                    observer.observe(document, config);

ポリフィルを使用して、または使用せずに、新しく作成されたオブジェクトにアクセスできる最小量のコードはどれくらいですか?

4

1 に答える 1

0

irc.freenode.net ##javascript から答えを見つけました: jaawerth

https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver

于 2016-02-17T22:17:49.590 に答える