No overloading of JavaScript no overloading function

Source: Internet
Author: User

In the ECMAScript language, the function name is simply a pointer (which can be considered a reference), the following code:

"Use strict"; function sum (A, b) {    return a+b;} Console.log (sum), var sum2 = Sum;sum = Null;console.log (sum2 (3,3));

Output: 3, 6;


The code can see that we define the function, in fact the function name is a pointer, pointer to the heap memory that block the definition of the function, we can save this address several.


Let's take a look at the "reload" (the quoted accent is not true):

"Use strict"; function Addsomenumber (num) {    return num + 100;} function Addsomenumber (num,add) {    return num + add;} Console.log (Addsomenumber (10));

What the result is:NaN


The above code can be equivalent to the following writing:


"Use strict"; var addsomenumber = function (num) {    return num + 100;}; Addsomenumber=function (num,add) {    return num + add;}; Console.log (Addsomenumber (10));

By this equivalent code, we can easily see that when we define a function with the same name, the equivalent function pointer points to other code definitions.

JavaScript no overloading function without overloading said

Related Article

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.