« Back to the index

Function.prototype.buildCompact examples

The "compact" method allow the programmer to build a parameterless function to be called for any callback use:
newfunction = function.buildCompact(parameters);
The parameters are the same parameters as the main function in the same order.
This function is very usefull to make calls to a function by a timer or for events callbacks.

Let's use a basic function that calculates the difference between 2 values and put it in a desired division:
function test(var1, var2, divresult) { var result = var2-var1; // put the result into the result division WA.get(divresult).append('The result is: '+result); }
View the result of this code
The compact function will be called upon request:
var compact1 = test.buildCompact(1,5,'test1'); <!-- the button: --> <span class="button" onclick="setTimeout(compact1, 1000);">call the compact1 function with a timer (1s)</span>
call the compact1 function with a timer (1s) Clear the result area
The compact function will be called upon click:
var compact2 = test.buildCompact(5,1,'test2'); <!-- the button: --> <span class="button" onclick="compact2();">call the compact2 function on click</span>
call the compact2 function on click Clear the result area


« Back to the index