Gefahr von Namenskonflikten bei js scripting ?

FriedrichLaher shared this question 1 year ago
Answered

auf welcher "Ebene" befindet man sich eigentlich wenn man Objecte mit javascript Skripten belegt?

Besteht Gefahr von Namenskonflicten, außer mit eigenen globalen Variablen und Funktionen?


( Frage ist profilaktisch, bisher noch kein Problem gehabt - oder kann es auch passierren daß kein geogebra keinen Fehler meldet aber unerwünschetes , unerklärliches Verhalten auftritt ? )

Comments (5)

photo
1

I think it's best to always use local variables.


If you need a global you could try eg

ggbApplet.myGlobal = 1;

photo
1

in geogebar5 script, this does not work. that is, if you define a variable ggbApplet.myGlobal = 1, you can not use it in another button scritp.

but you can define a function(method), function is "global".

photo
1

I found this thread looking for fixing to the issue explained in https://help.geogebra.org/t....


The command suggested by Michael works on GeoGebra 6 (it doesn't work in GeoGebra 5).


ggbApplet.myGlobal = 1;


To create a global array using this method doesn't work (neither in GeoGebra 6).


ggbApplet.myGlobalArray = [[1, 2, 3], [2, 3, 4]];


However, if I write

myGlobalArray = [[1, 2, 3], [2, 3, 4]];


in the declarations section of the Global Javascript tab, my applet seems to work fine. Could I get a side effect from this practice? Or could I use this method?

photo
1

Here is an example of my applets: the global array works fine.

photo
photo
1

Thanks Michael, and you just even answered what my nex question woul have been - if it's ok to burden ggbApplet with properties for own purposes.

© 2020 International GeoGebra Institute