But today I’m not gonna talk about everything of that Module Pattern. Today I’m gonna show you how you can create private functions and public methods.
A private functions is private, because it is not accessible form outside the module.
A public method is just like the private one a function. But a function inside a Object is called a method.
Maybe experienced developers will tell, my explanation is to easy. Please explain in the comments!
Enough talking, just dive into the code!
Let’s create a module called MrFrontendModule.
console.log(‘Title: ‘, MrFrontendModule.getTitle());`
And that is expected!
What if we try to call the function
console.log(‘Title: ‘, MrFrontendModule.addEmoticon());```We will get this error:
"TypeError: MrFrontendModule.addEmoticon is not a function`
And that is correct because this function is not returned by the module, so basically hidden for everything outside the module.
So we can only call the function