Skip to content

Instantly share code, notes, and snippets.

@NevenLeung
Last active August 4, 2018 20:19
Show Gist options
  • Save NevenLeung/2041325a6146cdb535f02f959792622b to your computer and use it in GitHub Desktop.
Save NevenLeung/2041325a6146cdb535f02f959792622b to your computer and use it in GitHub Desktop.
IIFE module VS. ES6 module
let count = 0;
function get() {
return count;
}
function add() {
count += 1;
}
export { get, add };
// another file that import above file
// import * as counter from './counter.js';
// counter.add();
// counter.get(); // 1
let counter = (function () {
let count = 0;
return {
get: function() {
return count;
},
add: function() {
count += 1;
}
}
})();
counter.add();
counter.get(); // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment