我有一个包含多个函数的node.js 文件。假设每个函数都需要下划线模块。在每个函数中添加 var underS = require("underscore");
与声明单个 var underS = require("underscore");
对性能有何影响> 全局排名第一?哪个性能更好?
最佳答案
Modules are cached after the first time they are loaded. This means (among other things) that every call to require('foo') will get exactly the same object returned, if it would resolve to the same file.
所以基本上不会,不会影响性能。
关于javascript - 单个函数中 require node.js 模块与全局函数对性能的影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33853042/