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);

使用或不使用 polyfill 可以让我访问新创建的对象的最少代码量是多少?

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 回答