JSFiddle - React, Tailwind, and code Playground
HTML
<div id="dog1" class="dog">click me</div>
CSS
.dog {
background:#ccc;
color:#666;
border:1px solid #333;
width:100px;
height:100px;
text-align:center;
}
JavaScript
function Dog(name, id) {
this.name = name ? name : "spot";
this.id = id ? id : "dog";
this.el = document.getElementById(this.id);
this.el.addEventListener("click", this, false);
}
Dog.prototype = {
handleEvent: function (event) {
switch (event.type) {
case "click":
return this.speak();
}
},
speak: function () {
alert('TEST' + " " + this.name + " " + myDog.name)
console.log("this.name: " + this.name + "\nmyDog.name: " + myDog.name);
}
};
var myDog = new Dog("tye33", "dog1");