Why Are My Class Variables Not Working? [SOLVED]

I was having issues with a sketch I was working on, so I created this little test to try and narrow down the issue-- which is that this.x and this.y are both undefined, even though the Walker class has a constructor which sets them both to an initial value. Help, what’s going on here?

class Walker{
    this.x = 400;
    this.y = 400;

   console.log(this.x + ", " + this.y);

let w = new Walker();
w.display(); // prints `undefined, undefined`
1 Like

Bring the last 2 lines in a function setup() :

void setup() {
    let w = new Walker();

I should be able to create a new object outside of the setup function. In any case, I did that and I’m seeing the same behavior, as expected.

LOL omg…it was a typo: contructor should be constructor.