[英]What's the difference between using “exports” vs. “this” in Node.js modules?
[英]Is there a difference between requiring modules at the top of a file vs. inline with code
例如,假設您有一個在節點中編寫的CLI工具,該工具僅在傳遞特定標志時才需要加載模塊。
如果我在文件頂部有require('dependency')
或在分支內有它,是否有任何區別,即
if (theFlagWasPassed) {
const dependency = require('dependency')
}
就在這里。 幾乎每個程序員都會在前幾行中查找依賴關系。 內聯導入對於可讀性來說不是一個好主意。
還有一個性能問題(不能優化那么多,但這只是一個猜測),這就是為什么新的import
語句必須在最高范圍內的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.