-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathimport_mixins.html
More file actions
41 lines (36 loc) · 1.06 KB
/
Copy pathimport_mixins.html
File metadata and controls
41 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive HTML Example - Module</title>
</head>
<body>
<h1>Interactive HTML Example - Module</h1>
<button id="call-public-method">Call publicMethod()</button>
<p>Output: <span id="output"></span></p>
<script type="module">
// utils.js
const min = (arr) => Math.min(...arr);
// privateMethods.js
const privateMethod = () => {
return min([10, 5, 100, 2, 1000]);
};
// myModule.js
const myModule = () => ({
publicMethod() {
return privateMethod();
},
});
// main.js
const moduleInstance = myModule();
// UI elements
const callPublicMethodButton = document.getElementById('call-public-method');
const outputElement = document.getElementById('output');
callPublicMethodButton.addEventListener('click', () => {
const result = moduleInstance.publicMethod();
outputElement.textContent = result;
});
</script>
</body>
</html>