-
-
Save jjhoncv/8561500 to your computer and use it in GitHub Desktop.
Creación de módulos de una forma sencilla
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 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(); | |
}); |
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 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