Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript How to organise JS ?

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #186141
    Koopa
    Participant

    I read this

    However this isn’t working, because the var s is overwritten by each module.

    Does anyone has a better reliable module pattern ?

    #186143
    __
    Participant

    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;
    })();
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.