Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#11081 closed bug (patchwelcome)

noConflict leaves actually undefined variables set to undefined

Reported by: connorhd@… Owned by: connorhd@…
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 dmethvin

Owner: set to connorhd@…
Status: newpending

In IE 6/7/8 you can't delete elements from the window object. It is possible to delete "global" variables (there is a slight distinction there) but only if they were not declared as properties of window.

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?

comment:2 Changed 11 years ago by connorhd@…

Status: pendingnew

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 dmethvin

Resolution: invalid
Status: newclosed

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 connorhd@…

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 dmethvin

Resolution: invalid
Status: closedreopened

comment:6 Changed 11 years ago by dmethvin

Resolution: patchwelcome
Status: reopenedclosed

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.

comment:7 Changed 10 years ago by markelog

#14013 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.