Let's say I want to create two (or more) global functions from within a
closure, so they can both share some "private" variables and methods. What
is the recommended way to do this?
(function(){
var message = "hello!";
window.showMessage = function() {
alert(message);
}
window.setMessage = function(str) {
message = str;
}
})();
Assuming a browser context (and therefore window. global ref) is this the
best way to do it?
I realize I could create it as a class with these as "static methods" of the
class, but I am re-writing someone else's code and need to maintain the same
global function interface (for now).
--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com