Mozilla Developer Network には、MutationObserver の使用方法の例があります。
// select the target node
var target = document.querySelector('#some-id');
// create an observer instance
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation.type);
});
});
// configuration of the observer:
var config = { attributes: true, childList: true, characterData: true };
// pass in the target node, as well as the observer options
observer.observe(target, config);
// later, you can stop observing
observer.disconnect();
config
変数はObject
. しかし、クロージャーコンパイラーは怒って、
エラー - MutationObserver.prototype.observe の実パラメータ 2 が見つかった仮パラメータと一致しません
: {attributes: boolean, characterData: boolean, childList: boolean}
必須: (MutationObserverInit|null|undefined) observer.observe(node, config);
externs/html5.jsに設定されているとおりです。
ただし、「Uncaught ReferenceError: MutationObserverInit が定義されていない」ため、MutationObserverInit タイプのオブジェクトをインスタンス化する方法が見つかりません。
ここで何をするのが正しいですか?