Skip to content

Instantly share code, notes, and snippets.

@royhowie
Created June 28, 2015 21:18
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 royhowie/86c25545ed21db78ede6 to your computer and use it in GitHub Desktop.
Save royhowie/86c25545ed21db78ede6 to your computer and use it in GitHub Desktop.
new es6 import syntax
// example1.js
import something from 'myModule'
console.log(something)
// this yields (note how `c` is not here):
/*
{
a : true,
b : 42,
d : 'some property only available from default'
}
*/
// example2.js
import something, { c } from 'myModule'
console.log(something) // same as above; the `default` export
console.log(c) // c === 'hello, world!'
// example3.js
import { a, b, d, default as something } from 'myModule'
console.log(a) // a === true
console.log(b) // b === 42
console.log(d) // d === undefined (we didn't export it individually)
console.log(something.d) // something.d === 'some property...'
// myModule.js
export let a = true
export let b = 42
export let c = 'hello, world!'
// `d` is not exported alone
let d = 'some property only available from default'
// this uses the new object literal notation in es6
// {myVar} expands to { myVar : myVar }, provided myVar exists
// e.g., let test = 22; let o = {test}; `o` is then equal to { test : 22 }
export default { a, b, d }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment