In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to call functions in external web development". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to call functions in external web development".
I. function
A piece of code with a specific function, the function simplifies the code, improves the reusability of the code, increases security and simplifies the operation. It includes modifiers, return value types, function names (parameter list, {, function body, executed code,
The returned value of return,}, and so on. Specifically:
Modifier: determine the scope of application of the current function, generally using public (public), which will not be discussed here.
Return value type: prompt the type of the return value of the current function. The return value may not exist, but it must be given. Even if there is no required void, write the corresponding return value type.
Function name: the name of the current function, can not be omitted, like a naming rule, need to follow the principle of small hump (a function name can be composed of multiple words, except the first word, all the first letters are capitalized. It should be noted that the function name should be as clear as possible.
Parameter list: there can be 0 or more data passed into the function when executing the function, and multiple parameters need to be separated. If there are no parameters, the parentheses after the function name cannot be omitted.
Function body: the place where the function is really realized.
Execute the code: the function implemented.
Return return value: return can be understood as a verb, meaning to throw out, throwing the data into the position of the return value type, and the outside world will receive the value. What you need to note is the features of return, including:
(1) you can pass the value out of the function.
(2) return means ending, and no more code can be written later.
(3) if the function has a return value, make sure that there is a return value in all cases.
Note:
(1) if there is no return value, you do not need to write return. If there is a return, it can only be followed by one value.
(2) return also means ending, and the following code will not be executed again.
Therefore, when we create a function, we require each function to complete a function as far as possible, emphasizing the singleness of the function.
Second, the call of function
Method: name of the function + ()
Note:
1. The call to the function can be nested, and the definition of the function cannot be nested.
two。 The functions we define must be implemented by calling.
3. It is called function in process-oriented and method in object-oriented.
Third, formal ginseng
The actual reference means the actual parameters. A formal parameter means a formal parameter that must be played by receiving the actual parameter. When applying the actual parameter, the formal parameter problem should pay attention to that their number, position and type must be consistent. In the actual assignment process, the program will pay the value of the actual parameter to the formal parameter in turn.
Function example: use the function to find the maximum of two numbers. The analysis is as follows:
1. First write a function with no parameters and no return value.
two。 Throw the function of finding the maximum of two numbers directly into the function.
3. Optimize the function.
Global variables and local variables
Global variables: generally, the variables defined directly in the class are called global variables.
Local variables: we will define variables and parameters within functions, for,if, etc., as local variables.
Note that all we can see directly inside a class is the definition of global variables and functions. The process from defining the current variable to being destroyed is the entire life cycle. Its scope lies in the scope to which variables can play a role in the life cycle. We can subdivide it into two parts: the scope of global variables and the scope of local variables.
The scope of a global variable includes the entire class, except for static-decorated methods. The scope of a local variable starts from defining the current variable to the end of its function, for,if, etc. When the life cycle of a variable ends, it means that the variable is released. The difference is that the scope of the function is different, the default value is different, if the global variable is not assigned, the system will give the default value-0, the local variable must be assigned before use.
5. Heavy loading
For functions in the same class, the name of the function is the same, but the parameters are different, so we call their relationship overloaded. Why can I have the same name here? Because when the function is really identified inside the program, it is the function name + the type of all parameters. But it is worth noting that overloaded functions are essentially different functions.
We might as well conclude that the function name must be the same. Parameters must be different (type, number, location), but independent of the name of the parameter. Overloading has nothing to do with the return value.
Thank you for reading, the above is the content of "how to call functions in external web development". After the study of this article, I believe you have a deeper understanding of how to call functions in external web development, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.