gpt4 book ai didi

javascript - let 语句应用后果

转载 作者:行者123 更新时间:2023-12-03 09:33:14 24 4
gpt4 key购买 nike

found这样解释为什么在 Node 中使用 var 声明的变量的循环比在 chrome 中更快:

Within a web browser such as Chrome, declaring the variable i outside of any function’s scope makes it global and therefore binds it as a property of the window object. As a result, running this code in a web browser requires repeatedly resolving the property i within the heavily populated window namespace in each iteration of the for loop.

In Node.js, however, declaring any variable outside of any function’s scope binds it only to the module’s own scope (not the window object) which therefore makes it much easier and faster to resolve.

对 Ecmascript6 中的 let 语句感到好奇:它是否可以在循环中使用更多 block 作用域声明的变量来加快计算速度,还是只是防止名称冲突的安全措施?

最佳答案

let 的目标是在 JavaScript 中拥有更好的作用域机制(不再仅仅为了作用域而将东西包装在匿名函数中)。任何性能提升都是锦上添花。

关于javascript - let 语句应用后果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31426444/

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