A simple question to better understand the this Keyword in PlayCanvas.
In this code:
var MessageReceiver = pc.createScript('messageReceiver');
MessageReceiver.prototype.initialize = function () {
// method to call when receiving message
// the this keyword always point to the object calling the method
console.log (this);
var self = this;
var onReceiveMessage = function()
{
self.entity.enabled = false;
console.log (this);
};
In the first console.log, the this keyword points to the ScriptType object.
In the second console.log (inside OnReceiveMessage), the this keyword points to the Application object.
If that means that OnReceiveMessage is called by the Application object, why is it so?
Thanks.