Hungrycop Posted December 12, 2014 Report 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. Quote Link to comment Share on other sites More sharing options...
rich Posted December 12, 2014 Report 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. Quote Link to comment Share on other sites More sharing options...
Hungrycop Posted December 12, 2014 Author Report Share Posted December 12, 2014 But why should I use this instead of 'r' ? Quote Link to comment Share on other sites More sharing options...
rich Posted December 12, 2014 Report 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. Quote Link to comment Share on other sites More sharing options...
Hungrycop Posted December 12, 2014 Author Report Share Posted December 12, 2014 thanks for answer! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.