你好,我只是想知道在 NodeJS 的 require
中实现这种逻辑是否存在任何性能问题、优点/缺点或大小。
附件A
const a = require('模块');
附件B
const a = require('module').function;
最佳答案
Nodejs 中的
require
是:
Node.js follows the CommonJS module system, and the built-in require function is the easiest way to include modules that exist in separate files. The basic functionality of require is that it reads a javascript file, executes the file, and then proceeds to return the exports object.
因此,按照 require
所做的,它不会影响性能。
注意:
When You are using core Module like
lodash
then including the directmodule
its affect performance.Because You see in lodash there are different file/folder for each function. So its always good practice to include only the function from module which is required.
示例:
const {get, isEmpty} = require('lodash');
关于node.js - `require("模块的差异") ;` to ` 需要 ("module").function;`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52736036/