ecmascript-6 - es6 错误中的 Ready only 错误和 const
问题描述
我在尝试运行的此脚本中收到只读错误。
我正在尝试学习 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"); }
但我什至不在严格模式下。
解决方案
不能修改常量。改变:
const content = "";
content += "<div class='row'>";
到
let content = "";
content += "<div class='row'>";
推荐阅读
- python-3.x - 根据字典中数组中的值获取键
- pandas - 通过选择 pandas 中的最新数据框来过滤数据框
- azure - 如何在不使用 IIS 配置的情况下定义 Azure WebApp 用作预热请求的路径?
- java - 从 Log4j 迁移到 Log4j2 时的 RollingFileAppender 实现
- python - g2o - VertexSE3 和 VertexSE3Expmap 有什么区别?
- bind - 在 tmux 中绑定变音符号
- rust - 语法问题函数返回函数不清楚
- c# - 如何为 roslyn 使用 SyntaxFactory
- go - 如何在 GCP App Engine 上使用自定义 Go 构建标志和工具?
- node.js - 回调错误处理程序没有停止执行功能