Skip to content

Instantly share code, notes, and snippets.

@jjhoncv
Forked from erikfloresq/modulo.js
Last active January 4, 2016 03:19
Show Gist options
  • Save jjhoncv/8561500 to your computer and use it in GitHub Desktop.
Save jjhoncv/8561500 to your computer and use it in GitHub Desktop.
Creación de módulos de una forma sencilla
var Example = (function($){
var st = {
'link' : '#example'
},
dom = {},
catchDom = function(){
dom.link = $(st.link);
},
bindEvent = function(){
dom.link.on('click',fnExample);
},
fnExample = function(){
},
init = function(){
catchDom();
bindEvent();
};
return {
init : init
};
})(jQuery);
$(function(){
Example.init();
});
var new_module = function(){
// Variables settings
var st = {
container : '.example',
list : '.list',
years : 0,
numbers : []
},
dom = {},
catchDom = function(){
dom.container = $(st.container);
dom.list = $(st.list);
},
suscribeEvents = function(oP){
dom.container.on('click',{'years':oP.years}, eContainer);
dom.list.on('click', {'numbers':oP.numbers}, eList);
},
eContainer = function(e){
alert(e.data.years);
},
eList = function(e){
alert(e.data.numbers);
},
initialize = function(oP) {
$.extend(st, oP);
catchDom();
suscribeEvents(oP);
}
return {
init: initialize
}
}
var e = new_module();
e.init({years:4, numbers: Array(1,2,3) });
// un ejemplo del modulo
// http://jsfiddle.net/jjhoncv/qLShS/1/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment