> If you were creating a specialized code library, what method would you use
> to "namespace" all the functions in use by that library? Since functions are
> themselves globals, would you just create a single "master" object, itself
> global, with all other variables inside of it? Then, in commons use, either
> use this.fn() or libraryname.fn() all over the place instead of just fn()
> when you want to use a function? And something similar for any variables
> that are needed to control the operation of the code library (say it's a
> popup widget that needs to keep track of all the open popups and whether a
> particular popup template has been loaded via ajax or not)?
>
var o = { // global object
first: function (xyz) {
return xyz;
},
second: function (abc) {
return abc;
}
};
o.first(); // this executes the first function from above
o.second(); // this executes the second function from above
This works because the functions are members of a named object, therefore
the functions are references as object properties bound to the named object.
My suggestion is to never use this:
function nameof () {}
Instead always use either the form in the example or this form:
var asdf = function () {};
If this fails to answer your question please let me know.