I am currently learning about JavaScript object oriented programming and seem to have run into a problem I couldn't figure out by googling so I am gonna try stack-overflow though I rarely ask questions on forums.
Anyway, I ran into an error while playing with functions after trying to convert some old non OOP code into OOP code. Note there are probably more errors than just the one I am asking about so don't trust any of the code below. The error I am getting is an Uncaught TypeError: Cannot read property fadeInAnimations of undefined.
Also, all advice to improve this code is really appreciated.
let mainSection = {
msTime : 0,
fadeInAnimation : ((element, delayTime) => {
$(element).delay(delayTime).fadeIn(1000)
}),
mainPageElements : [`.traninigTimes`, `.registration`, `.trainingFee`].forEach((element) => {
this.fadeInAnimation.fadeInAnimations(element, this.msTime)
this.msTime += 1000;
})
};
this.fadeInAnimationis undefined. Could you please provide a minimal reproducible example demonstrating the exact problem.fadeInAnimationis a function, yet you're trying to use it as an object with afadeInAnimationsproperty?this.fadeInAnimations(element, this.msTime)?thislikely points to the global window object - and that doesn’t have a method calledfadeInAnimations. If you need to access the method from outside the context of this object, then that would bemainSection.fadeInAnimations