Greetings I am learning javascript now and I want to know how to implement modularity in it. I googled some but didn't fully understood the method.
So I kindly ask for help. How to make this work?
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test Modularity</title>
</head>
<body>
<button id="buttonFoo" type="button" onclick="foo()">Foo</button>
<button id="buttonBar" type="button" onclick="bar()">Bar</button>
<script src="main.js"></script>
</body>
</html>
main.js
import { foo } from './foo.js'
import { bar } from './bar.js'
foo.js
export function foo()
{
alert("FOO!");
}
bar.js
export function bar()
{
alert("BAR!");
}
When I click on the buttons I get this error in debug.
Uncaught ReferenceError: foo is not defined
Uncaught ReferenceError: bar is not defined
Thanks in advance for your time.