【发布时间】:2022-01-24 16:25:54
【问题描述】:
我正在尝试修复这个 Eslint 错误:
Expected an assignment or function call an instead saw an expression
关于如何容纳代码以使其在以下示例代码中不会出现错误的任何想法?
window.matchMedia || (window.matchMedia = function() {
if (!styleMedia) {
const style = document.createElement('style');
const script = document.getElementsByTagName('script')[0];
let info = null;
style.type = 'text/css';
style.id = 'matchmediajs-test';
script.parentNode.insertBefore(style, script);
info = ('getComputedStyle' in window) && window.getComputedStyle(style, null) || style.currentStyle;
styleMedia = {
matchMedium: function(media) {
const text = '@media ' + media + '{ #matchmediajs-test { width: 1px; } }';
if (style.styleSheet) {
style.styleSheet.cssText = text;
} else {
style.textContent = text;
}
return info.width === '1px';
},
};
}
return function(media) {
return {
matches: styleMedia.matchMedium(media || 'all'),
media: media || 'all',
};
};
}());
知道为什么我会收到此 lint 错误吗?
谢谢
【问题讨论】:
标签: javascript reactjs eslint lint