只读错误和es6错误中的const

问题描述 投票:0回答:1

我正在尝试运行的此脚本中收到只读错误。

[我正在尝试学习const和新的es6,我不得不承认它非常简单,但是在这种情况下,我不能100%地确定这就是问题所在。

这是我的代码:

$(() => {
    const containerImage = document.querySelector( '.images' );
    const getPictures = () => {
        $.ajax({url: "https:myurl/photos.json", success: function(result) {
            const singleImage = result.photos;
            const content = "";
            content += "<div class='row'>";
            for(let i = 0; i < singleImage.length; i++){
                content.innerHTML += `<div class="col-md-4">
                <img src=${singleImage[i].image}>
                </div>`;
            };
            content += "</div>";
            containerImage.innerHTML = content;
        }});

    }
    getPictures();
});

有人在我的代码中注意到任何奇怪的东西吗?

加上控制台提及并抛出此错误:

function _readOnlyError(name) { throw new Error("\"" + name + "\" is read-only"); }

但是我什至不在严格模式下。

ecmascript-6 const strict
1个回答
0
投票

常量无法修改。更改:

const content = ""; 
content += "<div class='row'>";

to

let content = "";
content += "<div class='row'>";
© www.soinside.com 2019 - 2024. All rights reserved.