Skip to content

Instantly share code, notes, and snippets.

@JoanClaret
Last active August 29, 2015 14:15
Show Gist options
  • Save JoanClaret/b7e3129d5f6ef837c66c to your computer and use it in GitHub Desktop.
Save JoanClaret/b7e3129d5f6ef837c66c to your computer and use it in GitHub Desktop.
Multiple javascript encapsulation examples
// define components function
var components = (function($$) {
// define linkcolor function in components context
var linkColor = function(selector){
$(selector).click(function(e){
if ($$(this).hasClass('link-blue')){
console.log($$(this).attr('title'));
}
});
};
// define color functions in components context
var color = {
linkColor : linkColor
};
// define linkPosition function in components context
var linkPosition = function(selector){
$(selector).click(function(e){
console.log(e.clientX);
});
};
// define position functions in components context
var position = {
linkPosition : linkPosition
};
// define components methods
return {
color : color,
position : position
};
})($);
components.color.linkColor(".js-link");
components.position.linkPosition(".js-link");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment