jQuery source code analysis (4) - how to deal with $ naming conflicts

var _$ = window.$;
var jQuery = function(){};
jQuery.extend({
  noConflict: function(deep){
    if (window.$ === jQuery) {
      window.$ = _$;
    }
    if (deep && window.jQuery === jQuery){
      window.jQuery = _jQuery;
    }
    return jQuery;
  }
});
Load jquery and other libraries are also used after $,
var $ J = jQuery.noConflict ();    // define a new name 
$ J ( function () {});
If you want to continue to use $ in jQuery, the only need $ as a parameter,
jQuery.noConflict();
jQuery(function($){
  $('div').click(function(){ });
});

 

Guess you like

Origin www.cnblogs.com/easonw/p/11505328.html