Hungrycop Posted December 12, 2014 Share Posted December 12, 2014 Hi, I'm not native english speaker and I'm sorry for my english. I've got a question about phaser events. I can't understand how does it work:r.events.onOutOfBounds.add(this.resetRock, this);In the video course I watch teacher explained,that 'this' refers to r object but actually it refers to game object,event handler looks like this:resetRock: function(r){//some code}And the most amazing thing is that it doesn't matter what I pass r or this it works the same. Link to comment Share on other sites More sharing options...
rich Posted December 12, 2014 Share Posted December 12, 2014 `this` is the context (or scope) in which the function is called. In your code above it doesn't refer to the 'r' object, but the class in which 'r' lives. Link to comment Share on other sites More sharing options...
Hungrycop Posted December 12, 2014 Author Share Posted December 12, 2014 But why should I use this instead of 'r' ? Link to comment Share on other sites More sharing options...
rich Posted December 12, 2014 Share Posted December 12, 2014 Can I suggest you read through this excellent guide on JavaScript scope: http://toddmotto.com/everything-you-wanted-to-know-about-javascript-scope/ because it's all related to this. Link to comment Share on other sites More sharing options...
Hungrycop Posted December 12, 2014 Author Share Posted December 12, 2014 thanks for answer! Link to comment Share on other sites More sharing options...
Recommended Posts