简体   繁体   中英

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:

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

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.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM