node.js - `require("模块的差异") ;` to ` 需要 ("module").function;`

标签 node.js ecmascript-6

你好,我只是想知道在 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 direct module 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/

相关文章:

javascript - 在没有模板化表达式的情况下使用 ES6 模板文字语法有缺点吗?

javascript - 如果将项目放入数组并排序,则确定项目的潜在索引。

mysql - 我是否需要关闭nodejs+mysql中每个api的池连接

javascript - 如何提高JS函数式代码的性能

node.js - 通过socket.io向所有连接到nodejs服务器的客户端广播更新的数据

json - Node.js 和 JSON.stringify 缺少对象的一些值/参数

node.js - 从 AWS S3 Select 获取单个记录时获取 OverMaxRecordSize?

javascript - 有没有一种简单的方法可以在 Javascript 中完全卡住对象及其子对象(Deep Freeze)?

javascript - ECMA6 是否取消了使用原型(prototype)语法作为 JavaScript 中的最佳实践?

javascript - 使用过滤器和一些对象过滤另一个对象数组