I am trying to create two objects from one class. The objects add scroll listeners to the document and change change the divs provided by the instance.
However, creating a second class instance ignores the first and does not do anything to the provided div.
class MyClass{
constructor(parameter){
self = this;
self.parameterA = parameter;
self.myClassMethod = self.myClassMethod.bind(self);
document.addEventListener("scroll", self.myClassMethod)
}
myClassMethod(){
$('.class').each(function(){
console.log(self.parameter); //Returns only the second instance's parameter (parameter B)
$(this).children('.'+self.parameter).fadeIn('slow');//only fades in second instance
})
}
}
var testA = MyClass(parameterA);
var testB = MyClass(parameterB);
Edit: In this code I have to use the this
of the constructor and the .each()
function.