Skip to content

Instantly share code, notes, and snippets.

@cesarandreu
Created April 9, 2017 05:51
Show Gist options
  • Save cesarandreu/dee789c350fd13735306931e4e4bc822 to your computer and use it in GitHub Desktop.
Save cesarandreu/dee789c350fd13735306931e4e4bc822 to your computer and use it in GitHub Desktop.
/* 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