Created
March 30, 2018 07:59
-
-
Save mrpapercut/6d76c10a86c4b0f1610dfbaae8ce4471 to your computer and use it in GitHub Desktop.
ES Modules
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
class Counter { | |
constructor() { | |
this.n = 0; | |
} | |
count() { | |
return this.n++; | |
} | |
} | |
export default Counter; |
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
<!doctype html> | |
<html> | |
<head> | |
<title>ES Modules Example</title> | |
<script src="main.js" type="module"></script> | |
</head> | |
<body> | |
<textarea id="ta"></textarea> | |
</body> | |
</html> |
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
import Counter from './Counter.js'; | |
import {message} from './variables.js'; | |
class App { | |
constructor() { | |
this.counter = new Counter(); | |
this.message = message; | |
} | |
runCounter() { | |
let ta = document.getElementById('ta'); | |
window.setInterval(() => { | |
ta.value = this.counter.count(); | |
}, 1000); | |
} | |
} | |
const app = new App(); | |
console.log(app.message); | |
app.runCounter(); |
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
export const message = 'Hello world!'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment