This article mainly introduces how to understand the concept of function overloading in javascript through examples, which is very simple and easy to understand. If you need it, you can think of the function name as a pointer, it also helps to understand why ECMAScript does not have the concept of function overloading. Example:
The Code is as follows:
Function addSomeNum (num)
{
Return num + 100;
}
Function addSomeNum (num)
{
Return num + 200;
}
Var result = addSomeNum (100); // 300
Obviously, two functions with the same name are declared in this example, and the result is that the subsequent functions overwrite the previous functions. The above code is actually consistent with the following 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 observing the code after rewriting, you can easily see what happened. When creating the second function, it actually overwrites the variable addSomeNum that references the first function.
The above is all the content of this article. I hope you will like it.