gpt4 book ai didi

javascript - 为什么标签可以应用于所有语言语句?

转载 作者:行者123 更新时间:2023-12-05 04:19:56 26 4
gpt4 key购买 nike

According to the ECMAScript standard , 标签可以应用于所有语句。

这意味着以下行是有效的:

myLabel: throw 'whatever'

还有

function foo() {
myLabel: return 'whatever'
}

console.log(foo())

但这些标签似乎无法使用,这就引出了一个问题:为什么允许使用它们? (或者我有根本性的误解)

最佳答案

According to Brendan Eich, the author of JavaScript ,这种做法模仿了Java(1996年的新热),避免了“死标签分析”的需要:

Same as Java, IIRC. We didn't want to require engines to do dead label analysis. I know for sure I didn't want to when I first implemented in SpiderMonkey. This has led to unintended transposed javascript: labels (used to be URL schemes), but they're harmless.

关于javascript - 为什么标签可以应用于所有语言语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74616813/

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