Use requirejs and jquery, without clobbering global jquery?

前端 未结 3 1496
日久生厌
日久生厌 2020-12-03 07:39

I\'m using requirejs for the first time on a project. I\'m working in an environment that has a lot of Javascript in place already, and I\'m looking for clean ways to introd

3条回答
  •  时光取名叫无心
    2020-12-03 08:04

    Multiple versions of jQuery on one page is bad. Stop hacking and upgrade jQuery or use the older version.

    As for keeping $ safe try

    (function($) {
        // requirejs inclusion block for loading
    
    
    }(jQuery.noConflict(true));
    

    If you pass true to .noConflict it will replace the old jQuery variable and not destroy that globally.

    This means you can pass it in quietly. Say you have

    
    
                                     
                  
提交回复
热议问题