Created
April 9, 2017 05:51
-
-
Save cesarandreu/dee789c350fd13735306931e4e4bc822 to your computer and use it in GitHub Desktop.
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
/* CommonJS */ | |
// a.js | |
let a = 1 | |
module.exports = { a } | |
setTimeout(() => { | |
a++ | |
}, 100) | |
// index.js | |
const { a } = require('./a') | |
console.log(a) | |
setTimeout(() => { | |
console.log(a) | |
}, 200) | |
// OUTPUT | |
// > 1 | |
// > 1 | |
/* ES2015 Modules */ | |
// a.js | |
export let a = 1 | |
setTimeout(() => { | |
a++ | |
}, 100) | |
// index.js | |
import { a } from './a' | |
console.log(a) | |
setTimeout(() => { | |
console.log(a) | |
}, 200) | |
// OUTPUT | |
// > 1 | |
// > 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment