[icinga-users] var and locals keywords

Kai Nothdurft Kai.Nothdurft at Rantzau.de
Thu Nov 23 11:53:48 CET 2017


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 <tobias.koeck at gmail.com> 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




More information about the icinga-users mailing list