Skip to content

Instantly share code, notes, and snippets.

@rosalindwills
Last active August 29, 2015 14:26
Show Gist options
  • Save rosalindwills/2f01438b801a49433a1d to your computer and use it in GitHub Desktop.
Save rosalindwills/2f01438b801a49433a1d to your computer and use it in GitHub Desktop.
001B - A refactoring with the revealer module pattern
<!DOCTYPE html>
<html>
<head>
<title>001A</title>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
</head>
<body>
<input type="button" name="my-button" id="my-button" value="CLICK ME" />
<p>You have clicked <span id="click-count"></span> times.</p>
<script>
var ClickModule = (function(window, $) {
var clickCount, clickDisplay, clickButton;
var init = function() {
setupVariables();
}
var updateClickValue = function(e) {
clickCount++;
clickDisplay.html(clickCount);
}
var setupVariables = function() {
clickCount = 0;
clickDisplay = $('#click-count');
clickButton = $('#my-button');
clickDisplay.html(clickCount);
}
return {
init: init,
receiveElementClick: updateClickValue
};
}(window, jQuery));
$(document).ready(function() {
ClickModule.init();
$('#my-button').click(ClickModule.receiveElementClick);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment