Functions with the same name in javascript

I tried to write a function in a js file and another function with the same name on the page. I was expecting an error, but there was no error, and I only got the function from the js file to execute. How is this possible. Even if I write a function in a separate js file, everything will be displayed in a single html file. Then, as possible

<script type="text/javascript" language="javascript" src="JScript.js" />
<script language="javascript">
    function Boo()
     {
        alert("Hai new");
    }
</script>

<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Button runat=server OnClientClick="Boo();" Text="Click" />
    </div>
    </form>
</body>

and in js file

function Boo() {
    alert("Hai");
}
+3
source share
5 answers

, JavaScript, , , . JavaScript , JavaScript , , , . , myfunc (oneparm) myfunc (parmone, parmtwo) , , JavaScript, , .

http://javascript.about.com/library/blpolyfunc.htm

+10

javascript . , , . javascript.

+1

JS . , , . ( )

0

.

0

JavaScript (, ). .

In your case, I assume that the js file was downloaded after it function Boowas parsed inside html. Thus, when you click the button, the definition Booin the js file is the only one Boo.

0
source

Source: https://habr.com/ru/post/1747157/


All Articles