我只是想知道,希望有人能帮助我解决这个错误,我得到的提示是expected an assignment or function call and instead saw an expression
,该脚本可以正常工作,但是将其粘贴到jsfiddle.net时,我在行{{ 1}}关于为什么以及如何解决此问题的任何想法?
isObserving ? window.obs() : window.dis();
(function() {
var isObserving = false;
var target = document.getElementsByClassName('message')[0];
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.info("EVENT TRIGGERT");
});
});
var config = {
attributes: true,
childList: true,
characterData: true
};
window.dis = function() {
console.log('observer off')
observer.disconnect();
ars.innerHTML = "observer off";
};
window.obs = function() {
console.log('observer on')
observer.observe(target, config);
ars.innerHTML = "observer on";
};
window.toggleObserve = function() {
isObserving = !isObserving;
isObserving ? window.obs() : window.dis();
};
})();
var ars = document.getElementById("ars");
ars.addEventListener("click", toggleObserve);
// simulate change
refreshIntervalId = setInterval(function() {
document.getElementsByClassName('message')[0].innerHTML = Math.random().toString(36).substring(2, 15);
}, 1000);