$ node index.mjs
π module-a pre-export { name: 'module-a π', obj: { a: 'π¨π¦', b: 'bee', c: 'see' } }
π» module-b pre-export { name: 'module-b π»', obj: { a: 'π¨π¦', b: 'π', c: 'see' } }
{
moduleA: { name: 'module-a π', obj: { a: 'π¨π¦', b: 'π', c: 'π' } },
moduleB: { name: 'module-b π»', obj: { a: 'π¨π¦', b: 'π', c: 'π' } },
moduleObjectExport: { a: 'π¨π¦', b: 'π', c: 'π' }
}
Last active
June 7, 2021 21:28
-
-
Save mfdj/d7c443bf7c387ce92463adb77d16cf6f to your computer and use it in GitHub Desktop.
ECMAScript modules (ESM): Yes, when you export an object the reference is shared across all usages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import moduleA from './module-a.mjs'; | |
import moduleB from './module-b.mjs'; | |
import moduleObjectExport from './module-object-export.mjs'; | |
moduleObjectExport.c = 'π'; | |
console.log({ moduleA, moduleB, moduleObjectExport }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import obj from './module-scope-object-export.mjs'; | |
obj.a = 'π¨π¦'; | |
const result = { | |
name: 'module-a π', | |
obj | |
}; | |
console.log('π module-a pre-export', result); | |
export default result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import obj from './module-scope-object-export.mjs'; | |
obj.b = 'π'; | |
const result = { | |
name: 'module-b π»', | |
obj | |
}; | |
console.log('π» module-b pre-export', result); | |
export default result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
a: 'eh', | |
b: 'bee', | |
c: 'see', | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment