Normally, the passing parameters are written like this:
Copy codeThe Code is as follows:
Var numParameter = 123;
Function sendParameter ()
{
GetParameter (numParameter );
}
Function getParameter (sendNum)
{
Alert (sendNum );
}
Method A calls Method B and transmits parameters.
However, if the parameters of Method B are not fixed, different parameters may be required according to different situations. You can write the following:
Copy codeThe Code is as follows:
Var TXT parameter1 = "123 ";
Var txtParameter2 = "234 ";
Var txtParameter3 = "345 ";
Var txtSendParameter = "";
Var flag = 0;
Function sendParameter1 ()
{
Flag = 1;
TxtSendParameter = txtParameter1 + ";" + txtParameter2;
GetParameter ();
}
Function sendParameter2 ()
{
Flag = 2;
TxtSendParameter = txtParameter2 + ";" + txtParameter3;
GetParameter ();
}
Function getParameter ()
{
If (1 = flag)
{
// Goto functionC (txtSendParameter)
}
Else if (2 = flag)
{
// Goto functionD (txtSendParameter)
}
Else
{
Return;
}
}
You can pass the value without using global variables:
Copy codeThe Code is as follows:
Var TXT parameter1 = "123 ";
Var txtParameter2 = "234 ";
Var txtParameter3 = "345 ";
Function sendParameter1 ()
{
Var txtSendParameter = "1" + txtParameter1 + ";" + txtParameter2;
GetParameter (txtSendParameter );
}
Function sendParameter2 ()
{
Var txtSendParameter = "2" + txtParameter2 + ";" + txtParameter3;
GetParameter (txtSendParameter );
}
Function getParameter ()
{
Switch (arguments [0])
{
Case "1 ":
// Goto functionC (arguments );
Break;
Case "2 ":
// Goto functionD (arguments );
Break;
Default:
// Goto functionE (arguments );
}
}
Relatively speaking, arguments is a flexible object. Although it is not an array, it can use subscript values like array. Although it is a bit uncommon, it is still very useful.
Copy codeThe Code is as follows:
<Pre code_snippet_id = "179244" snippet_file_name = "external" name = "code" class = "javascript"> <pre code_snippet_id = "179244" snippet_file_name = "external"> </pre>
<Pre> </pre>
<Pre> </pre>
<Pre> </pre>
<Pre> </pre>
<Pre> </pre>
</Pre>