问题描述
我正在运行Edge / 15.15063。
为什么const不工作?
我怀疑Edge控制台在其封面下使用和
语句。这将解释 var
s和被提升到全局范围之外,但让
和 const
将被锁定进入区块范围:
with(...){
const x ='woo'
}
//下一个输入:
with(...){
console.log(x)//显然未声明
}
尝试在单线评估中以多线模式输入 - 他们应该在那里工作。
但你也是可能想要提交一个错误,因为控制台确实希望感觉就像评估全局范围内的东西一样。
I am running Edge/15.15063. 'Can I Use' says const should work.
Running:
const x = 'woo'
Then:
console.log(x)
Returns
'x' is undefined
Screenshot:
Why isn't const working?
I suspect that the Edge console is using a with
statement under its covers like other implementations did. This would explain var
s and even function
declarations being hoisted outside into the global scope, but let
and const
will be locked into the block scope:
with (…) {
const x = 'woo'
}
// next input:
with (…) {
console.log(x) // obviously undeclared
}
Try entering them in multiline mode, in a single evaluation - there they should work.
But you also might want to file a bug, as the console is indeed expected to feel like evaluating things in the global scope.
这篇关于const在Edge 15开发人员工具中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!