Update cookies preferences
Promotic

function - statement of language JavaScript

Description:
Definition of the function.
A function is a JavaScript procedure — a set of statements that performs a task or calculates a value. To use a function, you must define it somewhere in the scope from which you wish to call it.
Syntax:
function Name(Parameter1, Parameter2, ...)
{
  Statement1
  Statement2
  ...
}
Note:
Functions defined with function in the procedure are available only within the procedure.
Example1:
Function definition and calling:
Select and copy to clipboard

function Sum(a, b)
{
return a + b;
}

var c = Sum(1, 2);
Example2:
Definition of the onTick function for the AddEventTimer method with repeated calling terminated after 10 cycles.
JavaScriptSelect and copy to clipboard

function onTick()
{
Pm.Debug("nCounter=" + nCounter);
if (nCounter-- < 0)
{
pMe.Root.RemoveEventTimer(onTick);
}
}
var nCounter = 10;
pMe.Root.AddEventTimer(1000, 0, onTick);
Example3:
Adding a function into the onAction event of the PmfButton object.
Select and copy to clipboard

function onButtonUp(ev)
{
if (ev.Action == "main")
{
Pm.Debug("Click UP");
}
}
var oForm = pMe.Form;
var oBtn1 = oForm.CreateItem("button", "btn1");
oBtn1.AddEvent("onAction", "btn1", onButtonUp);
Example4:
The same example as Example3 but the function is not named and declared in advance.
It is created on the point of entry (this can be used only with simple functions).
Select and copy to clipboard

var oForm = pMe.Form;
var oBtn1 = oForm.CreateItem("button", "btn1");
oBtn1.AddEvent("onAction", "btn1", function(ev) { if (ev.Action == "main") { Pm.Debug("Click UP"); } });

History:
Pm9.00.05: The statement is supported in the PROMOTIC system
PROMOTIC 9.0.28 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.