简体   繁体   English

为什么我收到with语句的语法错误,但实际上并没有使用?

[英]Why I got this Syntax error of with statement, but i'm not actually using any?

In the following code, I'm not using any 'with statement', but when I set the breakpoint, it gives me the error: 在以下代码中,我没有使用任何“ with语句”,但是当我设置断点时,它给了我错误:

SyntaxError: 'with' statements are not valid in strict mode

(function () {
    'use strict';
    function addItem() {
        var orderListElement, newLi, childCount;
        orderListElement = document.getElementById('orderList');
        newLi = document.createElement('li');
        childCount = orderListElement.children.length;
        newLi.textContent = 'new item ';
        orderListElement.appendChild(newLi);
    }
    function deleteItem() {
        var orderListElement, lastLi;
        orderListElement = document.getElementById('orderList');
        lastLi = orderListElement.lastChild;
        orderListElement.removeChild(lastLi);
    }
    function registHandler() {
        var addItemButton, deleteItemButton;
        addItemButton = document.getElementById('addItem');
        deleteItemButton = document.getElementById('deleteItem');
        addItemButton.addEventListener('click', addItem, false);
        deleteItemButton.addEventListener('click', deleteItem, false);
    }
    window.addEventListener('load', registHandler, false);
}());

That's so annoying. 真烦人

This appears to be a known issue with Safari: https://bugs.webkit.org/show_bug.cgi?id=65829 这似乎是Safari的一个已知问题: https : //bugs.webkit.org/show_bug.cgi? id =65829

To reproduce the Error, you simply need to type any code into the console while stopped at a breakpoint and while in strict mode. 要重现该错误,您只需要在断点处停止和严格模式下在控制台中键入任何代码即可。

Here's the code from the bug report: 以下是错误报告中的代码:

(function(){
    "use strict";
    debugger;
})();

So when you're at the breakpoint, go to the console and type 2+3 (or any expression), and you'll get the Error. 因此,当您在断点处时,转到控制台并键入2+3 (或任何表达式),您将收到错误消息。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在使用 jest '??=' 进行测试时出现语法错误 - Why I got syntax error when doing test with jest '??=' 为什么我的 if 语句出现语法错误 - Why am i getting a syntax error on my if statement 我的异步 function 出现语法错误 - I got a syntax error in my async function 我想获取我的 Graph API 令牌,但出现错误,我正在使用 HttpServices 发出 POST 请求。 我收到 400 状态码。 我正在使用 NestJS - I want to get my Graph API token but I got an error, I'm making a POST request with HttpServices. I'm getting a 400 status code. I'm using NestJS 为什么在使用 Puppeteer 时出现超时错误? - Why I got the Timeout error when using Puppeteer? 为什么我收到错误“错误:语法错误,无法识别的表达式:不支持的伪:选择”? - Why I'm getting the error “Error: Syntax error, unrecognized expression: unsupported pseudo: select”? 不确定为什么将字符串传递给函数时出现语法错误 - Unsure why I'm getting a syntax error when passing string to function 为什么我在puppeteer中得到文件未定义错误? - Why I got document is not defined error in puppeteer? 为什么我得到这个类型错误而不是 javascipt 的构造函数? - why I got this type error not a constructor for javascipt? 为什么我有时会出错,有时不会? - Why i sometimes got error and sometimes not?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM