3 ms·
>> Unfortunately, the jQuery.noConflict(true) method breaks >> almost all plugins. NOT TRUE, if you know how to write plugins. Using some basic knowledge of Ja
by keeganwatkins 17y ago
>> Unfortunately, the jQuery.noConflict(true) method breaks >> almost all plugins.
NOT TRUE, if you know how to write plugins. Using some basic knowledge of Javascript (closures, scope, etc) this is very easy to remedy. The problem is that many are too lazy to avoid using the "$" alias, so plugins are often written to depend on it. If you take your "lazy" plugin and wrap in a closure, you can be sure that it will work even when jQuery.noConflict is called... yes, i can hear it now "but when true is passed to noConflict, even the global JQuery variable gets reassigned..." So? Read the source. It gets reassigned very predictably to _jQuery. So, write your plugins like this if you need to support cases where jQuery.noConflict(true) is called:
(function($) {
$.fn.lazyPlugin = function(opt) {
// ...
}
})(jQuery || _jQuery);