javascript - 是否可以从 JavaScript 中的 if 语句的主体将新字符串附加到 if 语句之外的变量?
问题描述
我试图用下面的代码完成的是在执行 if 语句时将单词“you”添加到变量“holis”中。
仅当满足 if 语句和随后的 console.log 时,我得到的结果是“嘿你”。
但是,当再次执行 SetTimeout 时,我会回到原来的“holis”变量(没有“you”)
JavaScript中有没有办法将字符串永久附加到字符串?我已经尝试过连接。
var holis = "hey"
if (this.txt2.substr(this.txt2.length - 3) === "...") {
this.txtElement2.innerHTML = `<span class="intro-text">${this.txt2}</span>`;
holis += " you"
console.log(holis)
} else {
this.txtElement2.innerHTML = `<span class="intro-text">${this.txt2}</span>`;
}
console.log(holis)
setTimeout(() => this.type2(), this.wait2);
}
谢谢!
解决方案
推荐阅读
- python - Docker python3:找不到'__main__'模块
- reactjs - 将 props 传递给 Field validate 会给出以前的 props 值
- sql - SQL Server 中的日期排序
- ruby-on-rails - 如何将 HTML 文件存储到 Rails 模型中
- javascript - node.js 无法正确执行的问题
- php - REST API Base64 图像 imagecreatefromstring():数据不是可识别的格式
- javascript - 检测两个元素重叠点
- python - 如何将简单的线性回归与梯度下降并行化 - 使用 numpy?
- r - 文本输出显示在 Shiny 应用程序 UI 的下一行
- python - Python-docx:如何将 StringIO 图像添加到 docx 文件中?