Skip to content

Instantly share code, notes, and snippets.

@machal
Created March 25, 2020 04:26
Show Gist options
  • Save machal/93552ee6d7656a6460cf7eb9aa060fd0 to your computer and use it in GitHub Desktop.
Save machal/93552ee6d7656a6460cf7eb9aa060fd0 to your computer and use it in GitHub Desktop.
ES6 modules basic demo for vzhurudolu.cz
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>
ES6 modules demo
</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="module" src="script.js"></script>
</head>
<body>
<main id="main" role="main" class="content">
<h1>
ES6 modules demo
</h1>
<p>
Open browser console.
</p>
</main><!-- /.content -->
</body>
</html>
// Vychozi export:
export default function() {
console.log('Default function')
}
// Export konsstanty:
export const hello = 'Hello!'
// Export funkce:
export function foo() {
console.log('foo');
}
// Funkce, ktera neni exportovana a zvenci je nedostupna:
function bar() {
console.log('bar');
}
// Importujeme:
import * as module from './module.js';
// Pouzivame:
module.foo();
console.log(module.hello);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment