Created
May 3, 2013 04:51
-
-
Save juliocesar/5507270 to your computer and use it in GitHub Desktop.
ES6 - modules
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
// ES6 modules | |
// ============= | |
// Compartments of code in ES6. Declared as strings with a keyword. | |
module 'fruit' { | |
export var list = ['Apple', 'Banana', 'Grape']; | |
export var makeSmoothie = function() { | |
// ... | |
} | |
} | |
// Modules can be nested: | |
module 'fruit' { | |
export var list = ['Apple', 'Banana', 'Grape']; | |
module 'smoothie' { | |
export var make = function() { | |
// ... | |
} | |
} | |
} | |
// Importing modules, also with a keyword. | |
import 'fruit' as fruit; | |
// fruit.list | |
// => ['Apple', 'Banana', 'Grape'] | |
// You can import with a string forward slash syntax: | |
import 'fruit/smoothie' as smoothie; | |
// ... and destructure as you import modules: | |
import {makeSmoothie} from 'fruit/smoothie'; | |
// typeof makeSmoothie | |
// => function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment