Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 (e.g. export default class Pikachu). How do I import it into another (main) file so that a user can access this class using e.g. 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?

like image 468
AKG Avatar asked Feb 08 '16 02:02

AKG


1 Answers

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.

like image 55
SLaks Avatar answered Oct 04 '22 19:10

SLaks