Last active
August 29, 2015 14:26
-
-
Save rosalindwills/2f01438b801a49433a1d to your computer and use it in GitHub Desktop.
001B - A refactoring with the revealer module pattern
This file contains hidden or 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
<!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