Skip to content

Instantly share code, notes, and snippets.

@premsh
Last active December 18, 2015 23:19
Show Gist options
  • Save premsh/5861031 to your computer and use it in GitHub Desktop.
Save premsh/5861031 to your computer and use it in GitHub Desktop.
Singleton Modular Pattern
var NewsWidget = (function () {
var s; // private alias to settings
function somePrivateFunction() {
alert("There are " + s.NumArticles + " articles");
}
return {
settings: {
numArticles: 5,
articleList: $("#article-list"),
moreButton: $("#more-button")
},
init: function() {
s = this.settings;
this.bindUIActions();
somePrivateFunction();
},
bindUIActions: function() {
s.moreButton.on("click", function() {
NewsWidget.getMoreArticles(s.numArticles);
});
},
getMoreArticles: function(numToGet) {
// $.ajax or something
// using numToGet as param
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment