Please have a look of the following code snippet,
I have a method someFunc of the Javascript class someClass
Inside the onclick handler of the btn variable inside the method definition, I want to get a reference to the SomeClass and the button both.
SomeClass.prototype.someFunc = function(){
var btn = document.crealeElement("button");
btn.onclick = function() {
this.somePropertyOfSomeClass = true; //this works, because bind
this.classList.add("active"); //this does not
}.bind(this);
}
I know, if I use bind(this) then the this variable inside the click handler refers to SomeClass, and without bind, it refers to the button element.
My problem is: How to get both? Because I want to some properties of the class SomeClass inside the handler
btn.classList...?