8

I'm working through Kyle Simpson's "You Don't Know JavaScript" series. At the end of (published 2014) "Scope & Closures" (p. 62), there is an example in ES6 of using the keyword "module" to import an entire module, like so:

// import the entire "foo" and "bar" modules
module foo from "foo";
module bar from "bar";

console.log(
    bar.hello( "rhino" )    
); 

foo.awesome();

This code doesn't work, however. My question is: is the module keyword something that was experimented with and dropped? Should I forget about this keyword?

1 Answer 1

5

They're typos

// import the entire "foo" and "bar" modules
import foo from "foo";  //fixed
import bar from "bar";  //fixed

console.log(
    bar.hello( "rhino" )    
); 

foo.awesome();

Sometimes, the examples in a book are not 100% accurate in typo, they really make confusion for the beginners.

Sign up to request clarification or add additional context in comments.

3 Comments

It doesn't seem to be a typo, though. Here is the paragraph that follows: "import imports one or more members from a modul's API into the current scope... module imports an entire module API to a bound variable..." This book was published in 2014. It feels like this was the proposed way to do it (in 2014), and they went with import only.
@zumafra you're right, I've re-read that book and I have to tell that, there's must be something wrong and the author's not always correct in everything. Btw, in order to import an entire module API to a bound variable, you could do so: import * as foo from 'foo'. Moreover, the way the author using export is also someway incorrect.
@zumafra You might notice that, this book is written and published in 2014 while the import/export syntax is officially available at ES2015 which means, the author just wrote this book based on a draft of ES2015, not the official one. And you might also notice that, the title of that section is Future Modules which discuss about the future of module management system in Javascript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.