Next lesson: Publisher/Subscriber pattern To the next lesson →
Lesson: Module Revealing pattern Repeat
Do you speak JavaScript?
In this video, we will be covering the Module Revealing pattern in JavaScript, a design pattern that allows for the creation of self-contained modules with a public and private interface.
The "Module Revealing Pattern" is a popular design pattern in JavaScript that combines the benefits of both object literal notation and the revealing pattern. The pattern reveals only the properties and methods that are meant to be public, while keeping everything else private and secure within the closure scope.
Here's an example of how you might implement the "Module Revealing Pattern":
function User(n) {
const name = n;
const sayHi = () => console.log(`${name}: hello`);
const secret = 'foobar';
return {
name,
sayHi
}
};
const a = User('Krasimir');
const b = User('John');
a.sayHi(); b.sayHi();
Practice is the fastest way to learn knowledge permanently. I have prepared a small task for you related to the lesson.
Materials related to the lesson:
→ Files associated with the lesson