DEV Community

loading...

Discussion on: What are CJS, AMD, UMD, and ESM in Javascript?

Collapse
mudlabs profile image
Sam

Because obj.js is exporting an object literal. The first time you require obj.js the object is instantiated, and assigned memory allocation. Every time you require it, it's the same object, from memory. If obj.js was exporting a function that returned an abject, well that would be different.

Collapse
karataev profile image
Eugene Karataev

If obj.js was exporting a function that returned an abject, well that would be different.

Agree. But in this case the exported function will be the same for all modules (i.e. the function will not be copied for every import).