Skip to main content

Bug Tracker

Side navigation

#11081 closed bug (patchwelcome)

Opened December 20, 2011 06:07PM UTC

Closed January 11, 2012 05:02PM UTC

Last modified June 12, 2013 07:22PM UTC

noConflict leaves actually undefined variables set to undefined

Reported by: connorhd@gmail.com Owned by: connorhd@gmail.com
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.$"

Attachments (0)
Change History (7)

Changed December 20, 2011 10:12PM UTC by dmethvin comment:1

owner: → connorhd@gmail.com
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?

Changed December 21, 2011 09:23AM UTC by connorhd@gmail.com comment:2

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.

Changed January 11, 2012 04:36PM UTC by dmethvin comment:3

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.

Changed January 11, 2012 04:51PM UTC by connorhd@gmail.com comment:4

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.

Changed January 11, 2012 05:01PM UTC by dmethvin comment:5

resolution: invalid
status: closedreopened

Changed January 11, 2012 05:02PM UTC by dmethvin comment:6

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.

Changed June 12, 2013 07:22PM UTC by markelog comment:7

#14013 is a duplicate of this ticket.