Side navigation
#14013 closed bug (duplicate)
Opened June 12, 2013 08:28AM UTC
Closed June 12, 2013 07:22PM UTC
Last modified June 18, 2013 06:51AM UTC
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@gmail.com | Owned by: | evgeniypavlyuk@gmail.com |
---|---|---|---|
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
Attachments (0)
Change History (6)
Changed June 12, 2013 06:14PM UTC by comment:1
owner: | → evgeniypavlyuk@gmail.com |
---|---|
status: | new → pending |
Changed June 12, 2013 07:22PM UTC by comment:2
resolution: | → duplicate |
---|---|
status: | pending → closed |
Duplicate of #11081.
Changed June 13, 2013 07:11AM UTC by comment:3
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.
Changed June 13, 2013 11:05AM UTC by comment:4
Perhaps you could submit pull request for us? Preferably with tests.
Changed June 13, 2013 02:17PM UTC by comment:5
Replying to [comment:4 orkel]:
Perhaps you could submit pull request for us? Preferably with tests.
Sure, I'll do this.
Changed June 18, 2013 06:51AM UTC by comment:6
Replying to [comment:1 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).
Do you have a use case where leaving these properties set to undefined on the window is an issue?