Decoding of overloading in JavaScript

Source: Internet
Author: User

In JavaScript there is a special data type---function type, and each function of JavaScript is an instance of the type of the functions. Because a function is an object, the function name is actually a pointer to a function object and is not bound to a function.

1<pre name= "code" class= "HTML" >functionsum (num1,num2)2 {3 returnNUM1 +num2;4 }5 6Alert (sum (10,10));// -7 varother =sum;8Alert (Other (10,10));// -9sum =NULL;TenAlert (Other (10,10));// -

The function name as a pointer to a function helps to understand why there is no concept of function overloading in ECMAScript

function sum (NUM1) {return num1 +100function  sum (NUM1) {return num1 +200 ;} Alert (sum);        //  -

Although two functions with the same name are declared, the following function overrides the previous one, which is equivalent to the code below

function sum (NUM1) {return num1 +100function(NUM1) {return num1 +200 ;} Alert (sum);        //  -

When you create a second function, you actually overwrite the first function variable sum of the reference

Search Number:ruixin, or scan the QR code below, follow the blog public number, irregular brain the Internet:

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.