开发者

Mixing jQuery and Prototype while preserving $ == jQuery

开发者 https://www.devze.com 2023-02-19 11:11 出处:网络
The common solution when mixing e.g. prototype and jQuery is using var $j = jQuery.noConflict(); to restore the prototype function $ and then using $j to access开发者_如何学编程 jQuery.

The common solution when mixing e.g. prototype and jQuery is using var $j = jQuery.noConflict(); to restore the prototype function $ and then using $j to access开发者_如何学编程 jQuery.

However, since prototype will be completely replaced with jQuery at some point, I'd prefer to use $ for jQuery and e.g. $p for prototype. Is this possible?

I know I could wrap my jQuery code in (function($) { /* my code */ })(jQuery); but I guess it'd be cleaner if I could get rid of the global $ var pointing to a prototype function.


Prototype doesn't have a mechanism to give up control of the $ function like jQuery does. Your best bet, as you note, is to wrap your jQuery code in a function that has $ locally defined to jQuery. Once you have all of the prototype code removed, you can remove the wrappers.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号