I don't use the module pattern often, so I am not able to answer all of your questions on this subject. I want to address your question regarding EmployeeModule || {}
I think it is easier to understand what that means in a regular context not using the module pattern. Consider this.
var foo = foo || {};
This is checking to see if foo
exists already. If so, we don't overwrite, we just set it equal to itself...the same as this:
var foo = {bar:'value'};
var foo = foo;
If foo doesn't exists, then we're creating a new object, like this:
var foo = {};
So, the code says "foo equals the previous foo (if foo is already something) OR a new object (if foo ISN'T already something)"
In your example, EmployeeModule || {}
is being passed into the instantly invoked function expression as a parameter called my
. If EmployeeModule
is something, that gets set to my
. If EmployeeModule
is nothing, then the value of my
is a new object.