1

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 タイプのオブジェクトをインスタンス化する方法が見つかりません。

ここで何をするのが正しいですか?

4

1 に答える 1

3

extern ファイルが間違っているので、修正する必要があると思います。

これは回避策です:

var config = /** @type {MutationObserverInit} */ ({ attributes: true, childList: true, characterData: true });
于 2015-04-30T10:06:03.753 に答える