pages

Sunday, September 26, 2010

vCO - functions in VMware Orchestrator

Sometimes you need a function to calculate a result and you don't want to use an action. Here we have an (sense free) example which shows us how a function is build up and used. Also the scope of used variables is demonstrated:



This example will log (in extra lines): 3, 4, 0, 7, 3, 4, 99

This show us the scope of defined variables. The variables a and b are defined in outer and inner (function) scope. The changed values (set to 99) will only affect the inner a and b. Otherwise c - there is no c defined inside the function or passed to it. So the outer c will be used.

After calling Add(a,b) the value of c is set to 99.

Regardless of the scope a function can return a value using the keyword return. There is no type definition. The function will return an object.

Warning - it is not recommended to manipulate outer variables from inside a function. It works, but making your code difficult to debug if any error or misbehavior occurs.

No comments:

Post a Comment