javascript - let 语句应用后果

标签 javascript node.js performance ecmascript-6

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/

相关文章:

javascript - 难以将快速 session 变量实现为数组

PHP 不会从 MySQL 中删除

javascript - HapiJS JSON 格式化

javascript - ipcMain.handle 内的 fs.readdir 不返回

Android 保存和加载图像的最有效方式是什么?

javascript - 在函数调用 Vanilla Javascript 中将数组转换为单个参数

javascript - SHA-256 密码生成器

node.js - Bigcommerce + Node.js

javascript - jQuery slideToggle() 性能不佳和/或卡住 IE8

java - OrientDB慢插入