Handling errors in jQuery(document).ready

前端 未结 5 664
庸人自扰
庸人自扰 2021-02-01 23:31

I\'m developing JS that is used in a web framework, and is frequently mixed in with other developers\' (often error-prone) jQuery code. Unfortunately errors in their jQuery(docu

5条回答
  •  不知归路
    2021-02-01 23:56

    I haven't tried this code, but it should work (at least, the idea should anyway). Make sure you include it AFTER jquery, but BEFORE any potentially buggy scripts. (Not necessary, see comments.)

    var oldReady = jQuery.ready;
    jQuery.ready = function(){
      try{
        return oldReady.apply(this, arguments);
      }catch(e){
        // handle e ....
      }
    };
    

提交回复
热议问题