The below code shows you a JavaScript Module (revealing pattern):
var module = (function(){
var _privateMethod = function(){
//code here
}
var publicMethod = function(){
//code here
}
return {
publicMethod: publicMethod
}
})();
The above revealing module pattern has a lot of advantages such as:
- Provides public & private methods (Encapsulation)
- App functionality can be divided into multiple modules
- Easier to scale and debug in future
So far I have been using the above Module Pattern within my apps and it has worked fine
Now I am trying to use AngularJs in my app. The thing thats confusing me is how to use the Angular Modules and JavaSscript Modules (see above) together?
A normal JavaScript Module (see above) provides encapsulation which is very important as JavaScript itself does not contain the private & public feature.
So my question is when working with angularJs modules is there any point of using JavaScript modules?
Should I divide my app functionality into angularJS modules?
Is there any difference between the angular modules we define & the JavaScript module pattern shown above?
I think the terminology "module" is confusing me. I apologise if this question seems too broad but even trying explain this question is hard for me.