JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js"></script>
<button id="button">
Increment A
</button>
<div id="id">
</div>
<script>
function outer() {
var a;
var b;
var $selector;
var retObj = {
init: function() {
a = 10;
b = 5;
$selector = $("#id");
attachEventHandlers();
}
};
function attachEventHandlers() {
$("#button").click(function() {
//place a debug point here and then in the console
//b would not be defined
//change the below statement to a = a+b, and in the console
//b would be defined with the correct value
a = a + 1;
$selector.html(a);
});
}
return retObj;
}
var obj = outer();
obj.init();
</script>