Hi, guys. I'm trying to make a simple game using this tutorial
https://gamedevacademy.org/html5-phaser-tutorial-spacehipster-a-space-exploration-game/
Most i've done, but i still CANT understand how to use this, what does it means in this case and what happens if aint use it? I read some documentation about this, but it's not helps me well. I'm using [preload.js -> boot.js -> menu.js etc] template. Actually most of my code works but i know how important to understand this topic.
In JavaScript, "this" refers to the calling context of the function. Unlike other more traditional languages, in JS it is only possible to know the value of "this" within a function by examining, at runtime, what called the function. Let's look at some examples:
function blah() { console.log(this.cats); }
window.cats = 'dogs';
var o = { cats: 'pants' };
blah(); // console logs "dogs"
blah.call(o); // console logs "pants"
blah.call({ cats: 'horse' }); // console logs horse
o.thing = blah;