ambiera home ambiera home

Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name:  Password:    
Ambiera Forum > CopperCube > Programming and Scripting
JS Actions: about the use of: me... or this...
Author Text

Registered User
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(); };


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);

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

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

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.

Registered User
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: "Interna?ional" (you are not logged in)




Forum Codes

Feature Code
Link [url] [/url]
Bold [b]bold text[/b]
Image [img][/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]



Software: Ambiera Light Forum. © 2008-2018 Nikolaus Gebhardt, Ambiera e.U.