Function declaration in a javascript flow element

Dear community,

If I define functions via function declaration in a javascript flow element, these functions are not available in the global scope. Why?


Above scripts are written in a javascript flow element of separate client actions. Implementation1 is not important for this question. Implementation2 uses function declaration and Implementation3 function assignment.

ThisIsMyFunction is available in global scope after executing Implementation3, but not by only executing Implementation2. I just wonder why. Can you explain that?

Currently I am rewriting existing code with function declarations to function assignments so that it works in OutSystems. But there must be a better alternative I thought.

Kind regards,
Jonathan Seesink


Hi Jonathan.

The reason is that they would pollute the global scope, and it would be difficult to locate where the function is being defined. You can define functions and use them but only in the scope of the Javascript node they were defined.

The alternative you might be looking for is the "Scripts" folder. Please read this documentation:

Each screen can import the required scripts, and use functions defined in the required script.


Thank you for the explanation!