In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use the function function in JavaScript. It is very detailed and has a certain reference value. Friends who are interested must finish it!
Any number of statements can be encapsulated by functions, and can be called and executed anywhere and at any time.
Our JavaScript scripting language is quite special, compared with the C language, its parameters do not need data type endorsement. Return the value return, I will not describe it too much, he is familiar with C language, if he does not write, he will automatically return undefined
Function fun (XBI y) {} / / is written like this to declare a function.
As far as I understand it, he passes in parameters in the form of an object, using the property values of the object (the value of the reference type) as my actual parameters.
For example, I have the following practices:
Function fun (x, y) {/ / alert (the value of "x is" + x.value); alert (the value of "x is" + x);}
When I do this, his pop-up error is: the value of x is [object HTMLInputElement], passed in as an object is not in line with my logical design, it should be the following.
Returns the value of my x.
Function fun (x, y) {alert (the value of "x is" + x.value); / / alert (the value of "x is" + x);}
So when I design a simple multiplication of two integer numbers, I return the value.
Here is a special memory to write this piece of html code in this tag. Otherwise, you will be looking for mistakes for a long time (don't ask me how I know, it's tears if you say too much)
We have a deep understanding, don't worry, and then take a look at this code:
Is there a different discovery here? according to the previous writing of this function, it must be scribbling, isn't it? But he can run here, laughing to death (laughing happily)
In other words, the ECMAScript function does not care how many arguments are passed in, nor does it care what parameters you pass in, and the parser will never complain. (so cool, the teacher doesn't have to worry that I won't pass parameters anymore), so how does he solve this "century puzzle"? in fact, inside every function, there is an arguments object to access the parameter array, thus getting every parameter passed to the array.
Taoist friends try to use double quotation marks fun ("brave", "Niuniu") for the following code fun function. Explain what will happen. Explain that the quotation marks are matched nearby, vuuuuuuuuuuuuuuuuuhhhhhhhhhhhh.
Ah, this and we learned that java function overloading is not a little bit of that flavor ah, in fact, JavaScript is not overloaded.
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); / / 20fun (10L20); / / 30
Can only pass in the number of parameters, to achieve the appropriate function, not to achieve the real sense of overloading, although the feature is not a perfect overload, but it is enough to make up for this regret of JavaScript. Arguments can also be used with parameters and
As follows:
Function fun (num1, num2) {if (arguments.length = = 1) {alert (num1 + 10);} if (arguments.length = = 2) {alert (arguments [0] + num2);}} fun (10); / / 20fun (10,20); / / 30
So there is a treasure to ask, anyway, the parameters are assigned in the arguments object, so is it feasible for me to modify the arguments [I] value directly?
What's interesting is that with regard to the arguments behavior, its value is always synchronized with the corresponding named parameter value, and it modifies the value in the current function! That is, the parameters are independent of the arguments memory space, but the values are synchronized
Function fun (num1, num2) {arguments [1] = 10; alert (arguments [0] + num2);}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.