However this isn’t working, because the var s is overwritten by each module.
?
If you mean that each sub-module/function will have access to s
, then yes, that’s the idea. It’s how they share settings.
If you mean that other (unrelated) modules would overwrite s
, then note you should be defining other settings vars for those objects. Alternatively (and this is my preference), wrap the whole module in an anonymous function expression so s
has closure.
var NewsWidget = (function(){
var s,
Newswidget = {
/* . . . */
}
// . . .
;
return NewsWidget;
})();