Using objGlobal to define commonly used functions

RAMP-NL

Using objGlobal to define commonly used functions


If you want to create a JavaScript function that is reused in many places you could do something like this in your sign-on script:

 

objGlobal.Mult = function (x,y) {

                 var z = x * y;

                 return(z);     }

 

objGlobal.Add  = function (x,y) {

                 var z = x + y;

                 return(z);     }

 

These operations define 2 functions in objGlobal named Mult and Add and the code that they contain.

Once this has been done the functions objGlobal.Add and objGlobal.Mult can be executed in other scripts like this:

 

var q = objGlobal.Add(222,3);

alert( q.toString() );

 

q = objGlobal.Mult(22,33);

alert( q.toString() );

 

which would display the results 225 and 726 respectively.