It is possible to use two version of jQuery without the use of jQuery.noConflict?
I already know how to use two version of jQuery using jQuery.noConflict()
method. But I really want to know if it is possible to build jQuery JavaScript source file without using the jQuery
or $
var开发者_JAVA百科iable names.
I would like to know if I can do something like:
<html>
<head>
<!-- This will set the variables: jQuery and $ -->
<script type="text/javascript" src="jquery-1.1.js"></script>
<!-- I would like to this next version do not use the variables: jquery and $ at all -->
<script type="text/javascript" src="jquery-1.5.js"></script>
</head>
</html>
The problem that I'm facing is that we're (our dev team) using Liferay and it comes with an old jQuery version, and I have no control to use the jQuery.conflict
, so I am wondering if I can build a jQuery version using a different name than jQuery.
Thanks in advance.
None that I know of. You are dealing with a versioning issue. The best bet is to find the dependencies on the old library and update them. Going forward, you carefully version the software to avoid this.
The solution you suggest, if it would work, which it won't, would bite you in the rear later anyway, as you would reach a day where 1.5 was the standard and people were using $ again. Only the code you wrote today would not have $ and you would need to version ahead again with 1.6 or 1.7 or whatever. then you end up with $ for 1.1 % for 1.x, etc. Ouch!
I don't get it. How is it possible that you are able to use a different name than jQuery for your other version, yet not add the .noConflict line of code? You are going to hand someone a new 1.5.js file right? Just throw this at the bottom of the file:
var $newNameSpaceHere = jQuery.noConflict();
change $newNameSpaceHere
to whatever you are using for 1.5
精彩评论