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
Flex layout is a commonly used layout method nowa...
Introduction to Docker Docker is an open source c...
In the previous blog, Xiao Xiong updated the meth...
The following script is used for scheduled backup...
Search online to delete duplicate data and keep t...
This article shares the specific code of Vue usin...
Table of contents Component recursive call Using ...
Now there are many WeChat public account operatio...
In the front-end layout process, it is relatively...
Table of contents Case Study Update account balan...
Index definition: It is a separate database struc...
The offline installation method of MySQL_8.0.2 is...
Messy log Nginx in daily use is mostly used as bo...
// It took me a whole afternoon to install this, ...
1. Nginx installation steps 1.1 Official website ...