Last active
August 29, 2015 14:15
-
-
Save JoanClaret/b7e3129d5f6ef837c66c to your computer and use it in GitHub Desktop.
Multiple javascript encapsulation examples
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
// 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