Where is the mistake in these 5 lines?

Hello, on the website after clicking on the link, but before opening the new page, you need to perform an action (assign to a class, which will start the animation at 400мс), after the animation you need to click on the address from the link. Wrote a function, but since just learning JS, you made a mistake, please tell me how to fix it and perhaps improve, if this is real... thank you in Advance!
$(".link").click(function(e){ //track any link of the plurality with a link class is clicked
 e.preventDefault(); //cancel action
 $("#page-wrapper").addClass("toback2"); // assigning class 
 setTimeout(function() { // delay for run-time animation
 location.href = this.href // go to original link
 }, 400);
});
June 14th 19 at 18:56
2 answers
June 14th 19 at 18:58
Solution
The context is lost. Do this:
$(".link").click(function(e){
e.preventDefault();
$("#page-wrapper").addClass("toback2");
 setTimeout(() => location.href = this.href, 400);
});

Or this:
$(".link").click(function(e){
e.preventDefault();
$("#page-wrapper").addClass("toback2");
 setTimeout(function() {
 location.href = this.href;
 }.bind(this), 400);
});
June 14th 19 at 19:00
Solution
this campaign was overridden by. before tamatam make the assignment self = this and use it
To do is bad practice, because during the timeout may be overridden self. - Tessie commented on June 14th 19 at 19:03
probably agree with you - Sonny.Skiles commented on June 14th 19 at 19:06

Find more questions by tags JavaScript