'Calling a class function inside of another function in the same class [duplicate]

I'm trying to do something in Javascript where I call a return function inside of another function, all within a class, it goes something like this:

class MyClass {
 constructor (x,y) {
  this.x = x;
  this.y = y;
 }

 newValues () {
  this.x = findNextXValue(this.x);
 }

 findNextXValue (x) {
  let changeVal = x + 5;
  return changeVal;
 }

}

When I try this code in p5js I get an error saying that findNextXValue is not defined. Why can't I do something like this? Any clarification would be appreciated, thanks.



Solution 1:[1]

Missing this should be...

this.findNextXValue(this.x);

But you really don't need to pass this.x either. Just access this.x in the function.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jackie