+ 1

Please solve my JavaScript problem

Please solve this (JavaScript) I want to make classes all with their own x varibles and their own Intervals to change them, but I am having a problem. When I write " this.x" it cannot find a varible. How can I get this varible? (Below prints NaN and I know the functions are working properly) function example(x) { this.x=x this.rightStart= function() { this.mover= setInterval( function() { this.x+=1 console.log(this.x) }, 10) } this.rightEnd= function() { clearInterval(this.mover); } }

4th Jan 2021, 9:49 AM
Cam UOR
Cam UOR - avatar
2 Answers
4th Jan 2021, 10:44 AM
JaScript
JaScript - avatar
0
Thank yous
4th Jan 2021, 11:41 AM
Cam UOR
Cam UOR - avatar