this contains all the properties of the class that you're accessing this from. As you can see, all your code is within the definition of the PlayScenePlayScene class that extends Phaser.ScenePhaser.Scene. Class properties are declared in the class, outside of any function, e.g.:
In the above case, classPropclassProp is accessed via this: this.classProp.
Now here's the tricky part. You can still set this.stars even if you never declared it. this.stars = 5; is valid, and the next time you access this.stars, you will get 5 instead of undefinedundefined. But, if you declare var stars; and then set this.stars = 5, these are two different variables! So when you access stars without this, you will get undefinedundefined. An example:
class Scene {
constructor() {}
create() {
let stars;
this.stars = 5;
console.log(`stars: ${stars}`);
console.log(`this.stars: ${this.stars}`);
}
}
const scene = new Scene()
scene.create();
class Scene {
constructor() {}
create() {
let stars;
this.stars = 5;
console.log(`stars: ${stars}`);
console.log(`this.stars: ${this.stars}`);
}
}
const scene = new Scene()
scene.create();