Last active
December 18, 2015 23:19
-
-
Save premsh/5861031 to your computer and use it in GitHub Desktop.
Singleton Modular Pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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