🔰module pattern
was used as a module system before the introduction of native JavaScript modules, implemented using IIFE.
replit:module pattern
// ⭐️ object returned by IIFE
// ⭡
// ╭ ╮ ╭─────────── ⭐️ IIFE ────────────╮
const foo = (function() {
// internal function
function sayHi(name) {
console.log(`Hey, my name is ${name}`);
}
// ⭐️ exposing the variables
return { sayHi };
})();
// ⭐️ accessing exposed methods
foo.sayHi("Bar");Last updated
Was this helpful?