Why are globals bad?

后端 未结 5 1665
鱼传尺愫
鱼传尺愫 2020-11-29 11:54

It totaly makes sense to me to use it here. What would be the alternative? How can i generaly avoid to use them and most of all why is it bad according to jsLint to make us

5条回答
  •  Happy的楠姐
    2020-11-29 12:48

    jsLint is very stringent. It's probably not necessary to get too hung up about it.

    But if you feel bad, you can do it just like how you scoped jQuery:

    (function($){
      $(function(){
       $.each(somearray ,(function($body){ $body.dosomething() })($('body'));
    
       if (something){
         $('body').somethingelse();
       }
    
      });
    }(jQuery));
    

提交回复
热议问题