#11081 closed bug (patchwelcome)
noConflict leaves actually undefined variables set to undefined
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
After including jQuery and using jQuery.noConflict(true); if $ and jQuery did not exist previously they will be set to undefined rather than being undefined.
This results in unexpected behaviour with "'$' in window" after using noConflict.
If the variables did not exist before jQuery was loaded they should be explicitly deleted with "delete window.$"
Change History (7)
comment:1 Changed 11 years ago by
Owner: | set to connorhd@… |
---|---|
Status: | new → pending |
comment:2 Changed 11 years ago by
Status: | pending → new |
---|
It tripped me up when using jQuery and Zepto.
I realise this is a slightly odd situation but I'm using the same code on mobile and desktop and due to doing slightly different things my code has ended up as:
<browser only>
Include jQuery My code using jQuery jQuery.noConflict();
</browser only> <common code (runs on browser and mobile>
Include Zepto My code relying on Zepto
</common code>
Zepto only sets $ if ('$' in window) is false, so my code ran fine on mobile but $ was undefined on desktop.
comment:3 Changed 11 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
This seems like something Zepto should handle, since we've worked this way since day one. I guess they don't have to worry about IE6/7/8 issues but we do.
comment:4 Changed 11 years ago by
Its a bit hard for Zepto to know what to do, if Zepto sees $ is set to undefiend how does it know whether I'm using $ for something else and undefined is a meaningful value for me, or its been "unset" by jQuery or similar.
comment:5 Changed 11 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
comment:6 Changed 11 years ago by
Resolution: | → patchwelcome |
---|---|
Status: | reopened → closed |
Sure, if there is a solution that preserves IE 6/7/8 compatibility we could include it. If not, you can just delete window.$
after your jQuery.noConflict()
call.
In IE 6/7/8 you can't
delete
elements from thewindow
object. It is possible to delete "global" variables (there is a slight distinction there) but only if they were not declared as properties ofwindow
.http://jsfiddle.net/CX3dk/
http://perfectionkills.com/understanding-delete/
I am not sure of the history of why the property is defined on
window
, or whether it is wise to change that.Is this affecting you in some way, or simply a sanitation thing?