Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#14013 closed bug (duplicate)

jQuery doesn't remember the fact of existence of the window properties $ and jQuery what leads to an issue in some cases after noConflict call

Reported by: evgeniypavlyuk@… Owned by: evgeniypavlyuk@…
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.1
Keywords: Cc:
Blocked by: Blocking:

Description

Hi there,

jQuery remembers the previous values of the global variables $ and jQuery. When noConflict is called, the previous values are restored.

But if the window properties $ and jQuery don't exist before jQuery inclusion, they become existing (with undefined values) after. If no conflict is called, the global variables are set to undefined. But the window properties keep existing.

A code like:

if (!('$' in window)) {

window.$ = somethingElse;

}

executes differently after jQuery inclusion with noConflict call.

I believe jQuery should first check whether the window properties $ and jQuery exist. And, if noConflict is called, and the global variables didn't exist, they should be removed (by calling delete $ - non-strict mode only, of course) rather than set to undefined.

Thanks, Evgeniy

Change History (6)

comment:1 Changed 6 years ago by timmywil

Owner: set to evgeniypavlyuk@…
Status: newpending

Do you have a use case where leaving these properties set to undefined on the window is an issue?

comment:2 Changed 6 years ago by markelog

Resolution: duplicate
Status: pendingclosed

Duplicate of #11081.

comment:3 Changed 6 years ago by evgeniypavlyuk@…

Sorry, I forgot you cannot delete a window property in IE6/7/8. What about to set $ and jQuery as global variables:

$ = jQuery = (function(window, undefined) {

var jQuery = function() {}; jQuery code. return jQuery;

})(window);

In this case it would be possible to delete these global variables if noConflict is called.

comment:4 Changed 6 years ago by markelog

Perhaps you could submit pull request for us? Preferably with tests.

comment:5 in reply to:  4 Changed 6 years ago by evgeniypavlyuk@…

Replying to orkel:

Perhaps you could submit pull request for us? Preferably with tests.

Sure, I'll do this.

comment:6 in reply to:  1 Changed 6 years ago by evgeniypavlyuk@…

Replying to timmywil:

Do you have a use case where leaving these properties set to undefined on the window is an issue?

I do. The case described above happened in a third party script on the client site. I had no access to the script. So I just changed my copy of jQuery so, that it sets properties $ and jQuery directly to my object instead of setting them to window and calling .noConflit(true).

Note: See TracTickets for help on using tickets.