1

В Mozilla Developer Network есть пример на how to use a MutationObserver.Каков способ использования MutationObserverInit с компилятором Closure?

// 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. Но закрытие компилятор рассердится и

ERROR - actual parameter 2 of MutationObserver.prototype.observe does not match formal parameter
found : {attributes: boolean, characterData: boolean, childList: boolean}
required: (MutationObserverInit|null|undefined) observer.observe(node, config);

Как установлено в externs/html5.js.
Однако, я не могу найти способ создать экземпляр объекта MutationObserverInit, потому что 'Uncaught ReferenceError: MutationObserverInit не определен'.

Какая повод сделать здесь?

ответ

3

Я думаю, что файл extern неверен и должен быть исправлен.

Это работа вокруг:

var config = /** @type {MutationObserverInit} */ ({ attributes: true, childList: true, characterData: true }); 
Смежные вопросы