[英]Node.js module.export vs export caching
在瀏覽了節點文檔后,我對緩存有了一點了解。 使用module.exports{constant_1, constant_2}
將緩存其分配的值,因此每次我們調用 require('') 時,它都會獲取緩存的值而不是創建一個新值。
example_1.js
const test = 'testValue';
module.export = {test};
example_2.js
const cachedValue = require('../example_1.js');
console.log(cachedValue);
但是當我們使用以下語法時會發生緩存嗎? 也導出{constant_1, constant_2}
語句?
example_1.js
const test = 'testValue';
export {test};
example_2.js
import {test} from "example_1";
console.log(test);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.