Closure Compiler 使用 MutationObserverInit 的方法是什么?
What is the way to use MutationObserverInit with the Closure Compiler?
在 Mozilla 开发者网络上,how to use a 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
。但是闭包编译器会生气并且
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 is not defined'.
在这里做什么是正确的?
我认为外部文件有误,应该修正。
这是解决方法:
var config = /** @type {MutationObserverInit} */ ({ attributes: true, childList: true, characterData: true });
在 Mozilla 开发者网络上,how to use a 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
。但是闭包编译器会生气并且
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 is not defined'.
在这里做什么是正确的?
我认为外部文件有误,应该修正。
这是解决方法:
var config = /** @type {MutationObserverInit} */ ({ attributes: true, childList: true, characterData: true });