Any number of statements can be encapsulated through functions and can be called and executed anywhere and at any time. Our function fun(x,y){ } //Write this to declare a function As far as I understand, he is passing in parameters in the form of objects, and using the various attribute values of the object (values of reference type) as my actual parameters. For example, I have the following approach: function fun(x, y) { // alert("The value of x is " + x.value); alert("The value of x is " + x); } When I do this, the pop-up box reports an error: The value of x is Returns my function fun(x, y) { alert("The value of x is " + x.value); // alert("The value of x is " + x); }
We have a deep understanding, don't worry, let's take a look at this code: Is there something different here? According to the previous way of writing this function, it must be written randomly, right? But it works here, so funny (laughing happily) That is to say, Fellow Taoists, try to use double quotes for the following code Hey, isn’t this a bit like the Let’s look at two more examples: function fun() { if (arguments.length == 1) { alert(arguments[0] + 10); } if (arguments.length == 2) { alert(arguments[0] + arguments[1]); } } fun(10);//20 fun(10,20);//30 It can only achieve appropriate functions by passing in the number of parameters, and it does not achieve real overloading. Although the feature is not a perfect overload, it is enough to make up for this regret of as follows: function fun(num1, num2) { if (arguments.length == 1) { alert(num1 + 10); } if (arguments.length == 2) { alert(arguments[0] + num2); } } fun(10);//20 fun(10, 20);//30 Then someone asked, the parameters are assigned to the
function fun(num1, num2) { arguments[1] = 10; alert(arguments[0] + num2); } </script> <form> <br><input type="button" onclick="fun(10,20)" value="click"> </form> The value in the pop-up box is 20. This shows that modifying the value of Summarize:
This is the end of this article about the detailed introduction of You may also be interested in:
|
<<: 12 Javascript table controls (DataGrid) are sorted out
>>: Example of Form action and onSubmit
The function to be implemented today is the follo...
Preface This article mainly introduces the releva...
1. Force no line break and end with an ellipsis. C...
In the latest HTML standard, there is a calc CSS e...
Table of contents Introduction Example: Event del...
Table of contents 1. Basic Examples 2. Computed p...
Why learn vim Linux has a large number of configu...
Scenario: The data in a table needs to be synchro...
Preface Components are something we use very ofte...
Table of contents Overview Environment Preparatio...
MySQL allows you to create multiple indexes on a ...
Table of contents Technology Stack Backend build ...
Network security is a very important topic, and t...
Table of contents Preliminary work Backend constr...
Table of contents 1. Proxy in LAN 2. Intranet pen...