Last active
August 4, 2018 20:19
-
-
Save NevenLeung/2041325a6146cdb535f02f959792622b to your computer and use it in GitHub Desktop.
IIFE module VS. ES6 module
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
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 |
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
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