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
1. Introduction When writing animation effects fo...
I have been taking a lot of MySQL notes recently,...
HTML imitates the Baidu Encyclopedia navigation d...
You can call it directly in the Linux shell envir...
Table of contents 1. What is redux? 2. The princi...
Table of contents 1. Introduction to import_table...
Excel is the most commonly used tool for data ana...
There is only one solution, that is to change the...
1.1 Copy the nginx installation package and insta...
Table of contents 2. Stack analysis using pt-pmap...
Find two test machines: [root@docker1 centos_zabb...
This article shares the MySQL 5.7.18 MSI installa...
brew install nginx Apple Mac uses brew to install...
Table of contents Installation-free version of My...