What happens if multiple scripts set [removed]?

前端 未结 4 1071
灰色年华
灰色年华 2021-01-24 00:41

There are a number of posts on StackOverflow and other websites regarding the problem of avoiding namespace collisions. In my scenario, I just want a method in my JavaScript to

4条回答
  •  情话喂你
    2021-01-24 01:25

    It'll be overriden . In Javascript, when you define handle event like

    window.onload = function(){
       console.log("in Load function 1");
    
    };
    window.onload = function(){
      console.log(" In load function 2");
    };
    

    That will make an " assign " window.onload => function() . And window.onload will be assign to last function .

    But in jQuery, You can handle event in many times and the browser will make all

    $("body").on("click",function(){
    console.log("make a callback function 1");
    });
    $("body").on("click",function(){
    console.log("make a callback function 2");
    });
    

    Because jQuery make a callback not "assign". Hope it helps you.

提交回复
热议问题