Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
JS Actions: about the use of: me... or this...

crusly
Registered User
Quote
2017-12-30 06:52:26

Hi Niko,

Watching the code on the action_DoLater.js , action_FadeScreen.js and others...(downloaded from CC website), and notice some parts the use of "me." instead of "this."


action_DoLater = function()
{
};

action_DoLater.prototype.execute = function(currentNode)
{
var me = this;
this.registeredFunction = function() { me.doLaterFunc(); };

ccbRegisterOnFrameEvent(me.registeredFunction);

this.startTime = (new Date()).getTime();
this.endTime = this.startTime + this.TimeMs;
this.currentNode = currentNode;
}


action_DoLater.prototype.doLaterFunc = function()
{
var now = (new Date()).getTime();

if (now > this.endTime)
{
ccbInvokeAction(this.ActionToDo, this.registeredFunction);
ccbUnregisterOnFrameEvent(this.registeredFunction);
}
}

This is necesary?.. or is used this way only for readability reason?

...There be any problem if only use this. on all the code?


niko
Moderator
Quote
2017-12-31 07:23:40

If you have a function created in there, like above in

this.registeredFunction = function() { me.doLaterFunc(); }; 


Then a reference to the this using a variable named for example me usually is necessary, because in JavaScript, for event handlers and similar things, the 'this' sometimes refers to the window object when executed. It's a strange "feature" of JavaScript, but that's how it is, unfortunately.


crusly
Registered User
Quote
2017-12-31 07:56:43

Thanks Niko for expain it...!

This help me to understand the code.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internationa?" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact