Skip to content

Instantly share code, notes, and snippets.

@juanbzpy
Last active December 10, 2015 21:58
Show Gist options
  • Save juanbzpy/4498584 to your computer and use it in GitHub Desktop.
Save juanbzpy/4498584 to your computer and use it in GitHub Desktop.
js patterns I use on my projects
var s,
NewsWidget = {
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
}
};
(function($){
var app = {
init: function(){
this.loadDefaults();
this.render();
this.doStuff();
},
loadDefaults: function(){
foo = $('#foo');
},
render: function(){
//show UI changes
},
doStuff: function(){
//do app stuff
}
};
app.init();
})(jQuery);
(function ($, App, window) {
'use strict';
var ready = false,
handler = function (e) {
},
init = function (page) {
if (ready) return;
// init stuff
$('.el').on('click', handler);
ready = true;
};
App.Subscribe('app/ready', init);
}(jQuery, App, this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment