gpt4 book ai didi

javascript - 标识符 'x' 已在 :1:1 处声明

转载 作者:行者123 更新时间:2023-12-02 21:53:40 25 4
gpt4 key购买 nike

所以我只是在学习如何编码,并且正在学习 Javascript 初学者指南,并有一个?。

我位于“此和绑定(bind)”部分,因此我尝试将对象绑定(bind)到函数,但不断收到以下错误:标识符“坐标1”已在以下位置声明匿名:1:1

我在实践中多次遇到同样的错误消息。我的代码如下所示。任何帮助是极大的赞赏。我知道这可能是一个简单、愚蠢的错误,所以我感谢您的回答!


let coordinates1 = {
x: 45.0,
y: 22.0
}

let coordinates2 = {
x: 12.6,
y: 22.7
}

function coordinateStatement (){
console.log ('The coordinates are ' + this.x + ', ' + this.y)
}

console.log(coordinateStatement())
console.log(coordinateStatement.bind(coordinates1)())
console.log(coordinateStatement.bind(coordinates2)())


最佳答案

letconst 变量根据设计不能重新声明。当您编写控制台代码时,您将其全部编写在同一范围内,从而导致变量被重新声明。将 let 更改为 var 或重新加载页面即可解决错误。

关于javascript - 标识符 'x' 已在 <anonymous> :1:1 处声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60061040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com