Hi Kai, just checked it out. It's possible to create a local variable with
locals.temp = a * b instead of var temp = a * b. The usage of the keywords locals, this and globals aren't necessary just for readability. As far as I have read there is a priority from locals to this to globals variables. If you just write 'something ...' = temp it will check out the different scopes and gets the first that fits. With the keyword you can force Icinga 2 to take a specific scope variable. Greetings Tobias On Thu, Nov 23, 2017 at 11:53 AM, Kai Nothdurft <[email protected]> wrote: > Hi Tobias, > > AFAIK the usage of the keyword "locals" is more or less for readability. > I'm not sure, if you can create the variable using your second example, but > you can access it in your function using "locals.temp" afterwards. If you > have already created variables named "temp" in different scopes, e.g. in > global and in local scope, Icinga2 will use automatically the variable from > the local scope, unless you use the "globals" specifier (globals.temp). The > use of "locals.temp" to access the variable named "temp" in the local scope > would make it more readable but otherwise makes no difference. > > best regards > Kai > > > >>> On 23.11.2017 at 09:48, Tobias Koeck <[email protected]> wrote: > > Hi Kai, > > > > thanks for the answer. > > > > I did read the 'manual / website documentation several times and I have > > understood the scope of local variables. > > > > It's possible to write the function either with > > > > function multiply(a, b) { > > var temp = a * b > > return temp > > } > > > > or with > > > > function multiply(a, b) { > > locals.temp = a * b > > return temp > > } > > > > Both 'creates' the local variable temp if it isn't available? So why use > > var if you can use locals.varname, too? > > > > Greetings > > Tobias > > > _______________________________________________ > icinga-users mailing list > [email protected] > https://lists.icinga.org/mailman/listinfo/icinga-users >
_______________________________________________ icinga-users mailing list [email protected] https://lists.icinga.org/mailman/listinfo/icinga-users
