which and how javascript function will be called if we have 2 function declarations with the same name?

前端 未结 6 1453
旧巷少年郎
旧巷少年郎 2021-01-14 04:58

Take a test:


6条回答
  •  感情败类
    2021-01-14 05:27

    function xyz() { .. } blocks are defined at parse time. If many functions have the same name, it's the last defined which takes the precedence.


    However, you can define functions at runtime using statements :

    var say = function() { alert( "ABOVE" ); }
    say(); 
    say = function() { alert( "BELOW" ); }
    

    will output ABOVE. (JSFiddle)

提交回复
热议问题