Transcript from the "ES6 Module Syntax" Lesson
>> Kyle Simpson: To bring modules into your syntax, to import them, there are two major styles of import. There's a bunch of variations, but two major styles of import. One is called the named import syntax which you see on line 1. I exported the default function, so technically its name is default from the outside, and then I decided to name that default import ask on line 1, which means now in my top level scope of where the import happened, I now have an identifier called ask, which is reference bound to the ask function inside of the module.
[00:00:38] That's what we sort of referred to as the Java style of import where import means literally to import identifiers into your scope. The second style, as you see on line 7, is referred to generally as the namespace import, which is to say I wanna get this whole module and collect all of its contents onto a single name spaced variable, in this case called workshop.
[00:01:19] And the named import syntax represents kinda the new school of thinking. It's not that one is right and one is wrong, but they're different ways of thinking about how you consume stuff. I certainly am in the camp that prefers to import a namespace, and then I have a thing called workshop, and then I have another thing called something else.
[00:01:40] That's the way my brain works, some people like the named imports, both syntaxes,thankfully. They weren't gonna do the name space import and then they added it at the last minute and I was so thankful because that's the way that I would prefer to deal with it. So there's your ES6 module syntax, such as it is, we're not expecting syntactic changes but there will be a variety of caveats when you're using it in node land.
>> Speaker 2: When you say you prefer the old module style you mean, the revealing module pattern in one file?
>> Kyle Simpson: The function wrapped around a couple slides ago.
>> Speaker 2: Thank you.
>> Kyle Simpson: Mm-hm.
>> Kyle Simpson: Specifically when I'm gonna do a module, I expose my modules as UMD style modules. That's the universal module definition. It's supposed to kind of inter-operate between browsers, module loaders and node. So that's the format I choose to write in.
>> Kyle Simpson: So whether you use a syntactic support in your language to define your modules, or whether you choose to hack it with the old school revealing module pattern, the same concept applies, which is that you're organizing a set of behavior into a cohesive unit hiding data in it and exposing a minimal necessary API.
[00:03:54] And if I were to boil down among the three pillars, this one is the most important. It's the one that touches everything else in such a foundational way. So hopefully that has provided you a better perspective on lexical skill.