Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Created May 3, 2013 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliocesar/5507270 to your computer and use it in GitHub Desktop.
Save juliocesar/5507270 to your computer and use it in GitHub Desktop.
ES6 - modules
// 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