In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to understand the basis of javascript object-oriented technology, in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Function
Javascript function I believe you have written a lot, so we are only a brief introduction here.
Create a function:
Function f (x) {.}
Var f = function (x) {.}
The above two forms can create a function named f (), but the latter form can create an anonymous function. When defining the function, you can set parameters. If the number of parameters passed to the function is not enough, they correspond in turn from the leftmost. The rest are assigned with undefined. If the parameters passed to the function are more than the number of parameters defined by the function, the extra parameters are ignored.
Js code
Function myprint (S1 string2 s2) {alert (S1 + "_" + S2 + "_" + S3);} myprint (); / / undefined_undefined_undefined myprint ("string1", "string2"); / / string1_string2_undefined myprint ("string1", "string2", "string3", "string4"); / / string1_string2_string3
Therefore, for a defined function, we cannot expect the caller to pass in all the parameters. Parameters that must be used should be detected in the function body. Operator), or set the default value and operate with the parameter or (| |) to get the parameter.
Js code
Function myprint (S1 must be input person) {var defaultperson = {/ / default person object "name": "name1", "age": 18, "sex": "female"}; if (! S1) {/ / S1) {/ / S1 is not allowed to be empty alert ("S1 must be input!"); return false;} person = person | | defaultperson; / / accepts the person object parameter alert (S1 + "_" + person.name+ ":" + person.age+ ":" + person.sex) | Myprint (); / / S1 must be input! Myprint ("S1"); / / s1_name1:18:female myprint ("S1", {"name": "sdcyst", "age": 23, "sex": "male"}); / / s1_sdcyst:23:male
The arguments property of the function
Inside each function body, there is an arguments identifier, which represents an Arguments object. Arguments object is very similar to an Array (array) object, for example, both have a length property, and access its value using the index using the "[]" operator to access the parameter value, but the two are completely different and have only superficial commonalities (for example, modifying the length property of an Arguments object does not change its length).
Js code
Function myargs () {alert (arguments.length); alert (arguments [0]);} myargs (); / / 0-undefined myargs ("1", [1m 2]); / / 2-1
The Arguments object has a callee property that indicates the method in which the current Arguments object is located. You can use it to implement internal recursive calls to anonymous functions.
Js code
Function (x) {if (x)
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.