因此,我只是在学习如何编码,并且正在通过Java初学者指南进行学习,并且使用了?。

我在“ This and bind”部分中,因此我尝试将一个对象绑定到一个函数,并且不断出现以下错误:标识符“ coordinates1”已在以下位置声明
匿名: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或重新加载页面以解决该错误。

10-06 15:13