简体   繁体   中英

namespace with ES6 modules

How do I assign a namespace using ES6 modules? I'd like to do with for example jQuery does, where the namespace is $ but doing it the intended ES6 way. All my modules are structured in separate files which export the classes/functions/whatever as default (eg export default class Pikachu ). How do I import it into another (main) file so that a user can access this class using eg Namespace.Pikachu ?

I have come to understand that it might have to do with named exports but I'm not quite totally sure how. Any help please?

If you use modules, you don't need namespaces.

The point of namespaces is to prevent conflicts between different files that define the same names.

Modules eliminate this problem entirely by letting the callsite choose a name to give each module it needs.

You just export a simple object with the things you want, and other files can import that to any name they choose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM