In my experience, most JS functions, constructor functions, or module-pattern functions, are declared as globals or are bound to a global namespace object. In any case, these identifiers are globally accessible.
From any line of code in your system you can have:
mod1 = somepackage.SomeModule(); // couple to me!
Here's a quick JS example, but in other languages the idea applies.
function A () { // couple to me!
return { foo: "bar" };
};
(function () {
function B () { // don't couple to me!
function c () { // really don't couple to me!
return "buzz";
};
return { fizz: c() }; // 0 scope lookup
};
var a = A(); // 1 scope lookup
var b = B(); // 0 scope lookup
})();
var a1 = A(); // 0 scope lookup
var b1 = B(); // B is not defined
Since globals are considered harmful, how much should visibility of functions/classes be restricted? What are the tradeoffs?
My question is somewhat motivated by: 'when are globals acceptable', 'alternatives to globals', and 'return of the globals'
Thanks!