😍IIFE=>Immediately Invoked Function Expression=>khởi tạo function & chạy ngay, import, export như nào
index.html
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Modules</h1>
<script type="module" src="app.js"></script>
</body>
</html>
file1.js
export const greet = (name) => {
return `Hello, ${name}!`;
};
file2.js
import { greet } from './file1.js';
const aa = (function () {
const message1 = greet('John 2');
return {
message1
}
})();
export default aa;
file3.js
import { greet } from './file1.js';
import aa from "./file2.js";
const bb = (function () {
const message2 = greet('John 3') + aa.message1;
return {
message2
}
})();
export default bb;
app.js
import bb from "./file3.js";
console.log(bb.message2)

Previous[JavaScript chuyên sâu]: Từ hàm IIFE tới Module PatternNextTìm hiểu về Higher-Order Functions trong JavaScript
Last updated
Was this helpful?