Javascript Internet Explorer for=>;的语法错误;签名
我使用以下脚本来检测开发人员工具是否打开: 它工作正常,但在IE11中它给了我=>的语法错误,我检查了许多其他问题,并认为它需要转换为函数,因此我更改了以下行:Javascript Internet Explorer for=>;的语法错误;签名,javascript,jquery,Javascript,Jquery,我使用以下脚本来检测开发人员工具是否打开: 它工作正常,但在IE11中它给了我=>的语法错误,我检查了许多其他问题,并认为它需要转换为函数,因此我更改了以下行: window.addEventListener('devtoolschange', event => { 到 现在在这一行上它没有给我语法错误,但是对于下面的代码,我不知道如何完全修改它,因为修改知识是很复杂的。如果有人能修复此代码,或者IE完全忽略此代码,我将不胜感激。我尝试检测IE,但它仍然读取代码并给出语法错误,下面是
window.addEventListener('devtoolschange', event => {
到
现在在这一行上它没有给我语法错误,但是对于下面的代码,我不知道如何完全修改它,因为修改知识是很复杂的。如果有人能修复此代码,或者IE完全忽略此代码,我将不胜感激。我尝试检测IE,但它仍然读取代码并给出语法错误,下面是根据函数()而不是=>,更改的代码,下面两行有=>
const emitEvent = (isOpen, orientation) => {
及
下面是以上行的完整代码
const emitEvent = (isOpen, orientation) => {
window.dispatchEvent(new CustomEvent('devtoolschange', {
detail: {
isOpen,
orientation
}
}));
};
const main = ({emitEvents = true} = {}) => {
const widthThreshold = window.outerWidth - window.innerWidth > threshold;
const heightThreshold = window.outerHeight - window.innerHeight > threshold;
const orientation = widthThreshold ? 'vertical' : 'horizontal';
if (
!(heightThreshold && widthThreshold) &&
((window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold)
) {
if ((!devtools.isOpen || devtools.orientation !== orientation) && emitEvents) {
emitEvent(true, orientation);
}
devtools.isOpen = true;
devtools.orientation = orientation;
} else {
if (devtools.isOpen && emitEvents) {
emitEvent(false, undefined);
}
devtools.isOpen = false;
devtools.orientation = undefined;
}
};
函数emitEvent(isOpen,orientation){
。也就是说,禁用开发工具通常是不好的做法,因为它会给你一种错误的安全感。它总是可以被绕过,只会让你自己作为开发人员的生活更加艰难。谢谢大家,Babel工作了:)@ivar它也可能特别烦人
const main = ({emitEvents = true} = {}) => {
const emitEvent = (isOpen, orientation) => {
window.dispatchEvent(new CustomEvent('devtoolschange', {
detail: {
isOpen,
orientation
}
}));
};
const main = ({emitEvents = true} = {}) => {
const widthThreshold = window.outerWidth - window.innerWidth > threshold;
const heightThreshold = window.outerHeight - window.innerHeight > threshold;
const orientation = widthThreshold ? 'vertical' : 'horizontal';
if (
!(heightThreshold && widthThreshold) &&
((window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized) || widthThreshold || heightThreshold)
) {
if ((!devtools.isOpen || devtools.orientation !== orientation) && emitEvents) {
emitEvent(true, orientation);
}
devtools.isOpen = true;
devtools.orientation = orientation;
} else {
if (devtools.isOpen && emitEvents) {
emitEvent(false, undefined);
}
devtools.isOpen = false;
devtools.orientation = undefined;
}
};