JSFiddle - React, Tailwind, and code Playground
by rhodee
HTML
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style type="text/css" media="all">
body {height: 100%}
#square {width: 50px; height: 50px; background-color: red;}
</style>
<title>Home</title>
<body>
<div id="square">
</div>
</body>
</html>
JavaScript
//Create a class object
function CountMe () {
//privately scoped variables
var elt = document.getElementById("square"),
clickCount = 0;
//priveledged methods
this.countClick = function () {
//who's context am I in?
this.addCount();
alert("you clicked me " + clickCount + " times!");
};
this.addCount = function() {
clickCount += 1
};
};
//Add an event listener for clicks //Create an instance of the class
var clickMe = new CountMe();
//clickMe.elt.addEventListener("click", clickMe.countClick, false);