Javascript-arguments implements function Overloading

Source: Internet
Author: User

Parameters 1. arguments

Object-oriented javascript has the characteristics of object-oriented languages: Abstraction. Using this, we have introduced in previous blogs about object creation, encapsulation, and inheritance, another one that is not involved is polymorphism. After reading the video, I still cannot find the knowledge of polymorphism in javascript.

Polymorphism means the same function name, but different classes have different executions. In javascript, we can see from the previous blog that subclass can inherit the parent class, but it does not rewrite the method of the parent class, but it is simply called. It is also found on the Internet. It is the same, and javascript is not polymorphism.

However, javascript is an interesting phenomenon in operations:No parameter is defined, but a parameter is called.

Functionbox () // we define this as follows: {return arguments [0] + '|' + arguments [1]; return arguments. length;} // However, alert (box ('aaa', '34') is called in this way; // aaa34 (output parameter) // 2 -- number of parameters (length)

Similarly, call (this, pro, pro2) can also be used in the subclass when calling the Inheritance (call ).

In javascript, function parameters are of no type and the number of parameters is arbitrary. An important object is used:ArgumentsWriting flexible functions should belong to the scope of function overloading. Let me understand this.

Ii. arguments implements function Overloading

How can we use arguments? Because javascript itself is a weak scripting language, there is no limit on javascript parameters. Therefore, the function overload implemented here is not as powerful as the general language, you can only select one parameter based on the number of parameters.

Since arguments can accept the passed parameters, you can determine the operation based on the number of passed parameters. For example, we can read the CSS style of a node based on the number of input parameters, or set the style of the node.

// Set cssbase.prototype.css = function (attr, value) {for (var I = 0; I
 
  

Summary:Although javascript is just a scripting language, many structures or languages, especially data types, do not like c #, c ++. java has a rigorous language structure and format requirements, however, the ease-to-learn feature makes javascript widely used. Javascript is involved at the beginning, but it only knows that it can help html achieve dynamic page effects. However, during the continuous learning of evil, it is found that javascript is really practical and easy to write, however, there are many functions available for us to call. At first, we only knew little about it, and simple page creation could not play its real level. After making a page with the video, I realized that javascript is a brilliant bridge to dynamically connect CSS and html. With it, you can make CSS and html more flexible.

Javascript is small but dirty. Functions, objects, BOM, DOM ...... Every one of these things is so popular, providing almost all the methods we want to operate html.

Sometimes, we are too hasty to take a look at this knowledge, ignoring a lot of things that originally existed, and turning around.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.