I am trying to practice writing object oriented code with javascript, but it's still confusing to me. I've seen some other people ask this question, but I haven't found a real clear answer. I have a property that has a nested function and I want to use one of the properties from the parent class.
var myClass = {
btn: document.getElementById('btn'),
color: "#000",
clickListener: function(){
this.btn.addEventListener("click", function(){
this.style.background = myClass.color;
});
},
}
This is the only way I can make it work, but it seems weird using the class name inside of the class. Is there a better way to do this or is this normal?