var mainObject = function(){
var constNine = 9;
var a = [1,2,3];
var key = 'abc';
function publicFunction(){
var x = 5;
return (x*a[0]*a[1]*constNine)+a[2];
}
function privateFunction()
{
var x = 5;
return (x+a[0]+a[1])*a[2];
}
return {
key: key,
publicFunction: publicFunction
}
}();
Here in the above code:
- mainObject is an object and is in window scope i.e. can be accessed from outside js as well.
- 'constNine' is integer value, not accessible in the window scope, can be used inside the mainObject only. It is a constant value 9.
- 'a' is an array and is not accessible in the window scope, can be used inside the mainObject only.
- 'key' is a string var and is in window scope.
- 'publicFunction' is a function and it is in window scope.
- 'x' is integer variable and is only accessible within publicFunction
- 'privateFunction' is a function and is not accessible in the window scope, can be used inside the mainObject only.
As javascript code grows, it would be really useful to put naming convention for all these JS variables and objects. Could someone suggest how should these be named i.e. should have underscore at start, should be camel case, should be all capital etc.?
I read several guides and questions like this but didn't get answer that covers all the above points.