var stateModule = (function () { var state; // Private Variable var pub = {};// public object - returned at end of module pub.changeState = function (newstate) { state = newstate; }; pub.getState = function() { return state; } return pub; // expose externally
}());
so
stateModule.changeState("newstate");
sets the stateand
var theState = stateModule.getState();
gets the state