Home > Web Front-end > JS Tutorial > Understand the concept of no function overloading in javascript through examples_javascript tips

Understand the concept of no function overloading in javascript through examples_javascript tips

WBOY
Release: 2016-05-16 15:57:06
Original
1040 people have browsed it

Imagining function names as pointers also helps to understand why there is no concept of function overloading in ECMAScript. Example below:

Copy code The code is as follows:

function addSomeNum(num)
{
Return num 100;
}
function addSomeNum(num)
{
Return num 200;
}
var result=addSomeNum(100);//300

Obviously, in this example, two functions with the same name are declared, and the result is that the later function overwrites the previous function. The above code is actually identical to the code below.

Copy code The code is as follows:

var addSomeNum=function(num)
{
Return num 100;
};
var addSomeNum=function(num)
{
Return num 200;
};
var result=addSomeNum(100);//300

By looking at the rewritten code, it’s easy to see what’s going on. When you create the second function, you actually overwrite the variable addSomeNum that references the first function.

The above is the entire content of this article, I hope you all like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template