const obj = {A: 2}
module.exports = obj
If another module imports from the above module, will it get a deep copy of obj
or just a reference?
const obj = {A: 2}
module.exports = obj
If another module imports from the above module, will it get a deep copy of obj
or just a reference?
Exports work exactly the same way as every other way of passing values around.
The value of obj
is a reference to the object.
A copy of that value (still a reference) is assigned to exports
.
Anything require
ing that module will get a copy of that value (still a reference).
I would say references because modules have their own execution context. meaning they track state of the context as you import / re import it.
He is an article that explain it better. https://krasimirtsonev.com/blog/article/javascript-module-system-for-state-management