Introduction to the parameter transfer of JS

Source: Internet
Author: User

Presumably we are not unfamiliar with the parameters of the transfer, this article for you to introduce the parameters of JS transfer, the need for friends can refer to the next

Normally, passing parameters are probably all written as follows:

The code is as follows:

var numparameter = 123;

function Sendparameter ()

{

GetParameter (Numparameter);

}

function GetParameter (sendnum)

{

alert (sendnum);

}

A very simple a method calls the B method and passes the argument.

However, if the parameters of the B method are not fixed, they may require different parameters depending on the situation, and can be written as follows:

The code is as follows:

var txtParameter1 = "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

}

}

So can you not use global variables to pass values:

Copy code code as follows:

var txtParameter1 = "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 very flexible object, although not array, but can use the same as the array of subscript value, although a bit rare, but still very good.

The code is as follows:

<pre code_snippet_id= "179244" snippet_file_name= "blog_20140207_4_1482200" name= "code" class= "JavaScript" > <pre code_snippet_id= "179244" snippet_file_name= "blog_20140207_4_1482200" ></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

<pre></pre>

</pre>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.