Skip to content

Instantly share code, notes, and snippets.

@mrpapercut
Created March 30, 2018 07:59
Show Gist options
  • Save mrpapercut/6d76c10a86c4b0f1610dfbaae8ce4471 to your computer and use it in GitHub Desktop.
Save mrpapercut/6d76c10a86c4b0f1610dfbaae8ce4471 to your computer and use it in GitHub Desktop.
ES Modules
class Counter {
constructor() {
this.n = 0;
}
count() {
return this.n++;
}
}
export default Counter;
<!doctype html>
<html>
<head>
<title>ES Modules Example</title>
<script src="main.js" type="module"></script>
</head>
<body>
<textarea id="ta"></textarea>
</body>
</html>
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();
export const message = 'Hello world!';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment