将正常功能(事件)替换为箭头功能会导致问题
Replaceing normal function (event) to arrow function causes issue
你好,我看到之前也出现过类似的问题。
我正在关注这个 tutorial。在本教程中,他使用
阻止了默认提交按钮教程
function addTodo (event) {
event.preventDefault();
}
我想将其转换为箭头函数。我试过这个:
let addTodo = (event) => {
event.preventDefault();
}
然后我得到一个错误:
Uncaught ReferenceError: can't access lexical declaration
假设完整的错误消息是 ReferenceError: can't access lexical declaration`X' before initialization。
函数声明已提升。
变量赋值不是。
在给它赋值之前,您无法阅读 addTodo
。
更改源代码的顺序。
使用 'const' 而不是 'let' 是否可以解决问题?
const addTodo = (event) => {
event.preventDefault();
}
你好,我看到之前也出现过类似的问题。
我正在关注这个 tutorial。在本教程中,他使用
阻止了默认提交按钮教程function addTodo (event) {
event.preventDefault();
}
我想将其转换为箭头函数。我试过这个:
let addTodo = (event) => {
event.preventDefault();
}
然后我得到一个错误:
Uncaught ReferenceError: can't access lexical declaration
假设完整的错误消息是 ReferenceError: can't access lexical declaration`X' before initialization。
函数声明已提升。
变量赋值不是。
在给它赋值之前,您无法阅读 addTodo
。
更改源代码的顺序。
使用 'const' 而不是 'let' 是否可以解决问题?
const addTodo = (event) => {
event.preventDefault();
}