Promotic

function - statement of language JavaScript

Description:
Function declaration.
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(par1, par2, ...)
{
  statement1
  statement2
  ...
}
Note:
Functions declared 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:
Declaration of the OnTick function by method AddEventTimer 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.27 SCADA system documentation MICROSYS, spol. s r.o.

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