Q: What would you name the local scope that is in a function that is inside of another function?
Let me explain:
I'm having trouble with the naming convention that I want to use. Here's a trivial example:
!function($, window, undefined) {
var Variables = {};
Variables.X = 1;
function myFunction() {
var local = {};
local.X = 2;
$('.myClass').each(function() {
var local = {};
local.X = 3;
});
}
}(jQuery, window);
Now, I've decided that I'm going to use the object called "Variables" to house all objects that are shared anywhere between functions. A global scope, if you will, limited to within the outer !function() {} definition.
And I've decided to use the object called "local" to house all the objects that are within a function. My problem is the scope of a function inside of a function. I think I have to somehow incorporate the name of the function in order to make it unique. I know that in this trivial example, local.X is two separate variables. But I want to name them separately so that it's more easily readable by a human. I don't want to come back 6 months from now and wonder what local.X is.
Adding to the problem is that it's an anonymous function, so there is no function name to tie into in order to make the "local scope" uniquely identifiable. I may have to make up a rule that if a variable is required inside a callback function, then give the callback function a name and tie the local scope to that name (somehow).