Forums

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

Home Forums JavaScript Structure of js code Reply To: Structure of js code

#151697
Kuzyo
Participant

Thanks @traq, I uderstood. I found similar solution, but without ** me**:

var NewsWidget = (function () {
    var s; // private alias to settings

    return {
        settings: {
            numArticles: 5,
            articleList: $("#article-list"),
            moreButton: $("#more-button")
        },

        init: function() {
            s = this.settings;
            this.bindUIActions();
        },

        bindUIActions: function() {
            s.moreButton.on("click", function() {
                NewsWidget.getMoreArticles(s.numArticles);
            });
        },

        getMoreArticles: function(numToGet) {
            // $.ajax or something
            // using numToGet as param
        }

    };
})();