I recommend adding/subtracting this.size when you meet the conditions. This will just move the circle slightly back into the canvas.
For example the first line could be
if ((this.x + this.size) >= width) this.x -= this.size;
Also, pay attention to correctly use this.x and this.y depending on horizontal or vertical conditions.
I hope that gets you further in the exercise.
Have a nice day,
Michael
PS: Your email address is visible in your post. I think it somehow ended up in the optional “name” field of your profile. I recommend removing it.