Created
June 28, 2015 21:18
-
-
Save royhowie/86c25545ed21db78ede6 to your computer and use it in GitHub Desktop.
new es6 import syntax
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
// 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' | |
} | |
*/ |
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
// example2.js | |
import something, { c } from 'myModule' | |
console.log(something) // same as above; the `default` export | |
console.log(c) // c === 'hello, world!' |
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
// 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...' |
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
// 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