#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: | Owned by: | ||
---|---|---|---|
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 follow-up: 6 Changed 10 years ago by
Owner: | set to evgeniypavlyuk@… |
---|---|
Status: | new → pending |
comment:2 Changed 10 years ago by
Resolution: | → duplicate |
---|---|
Status: | pending → closed |
Duplicate of #11081.
comment:3 Changed 10 years ago by
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 follow-up: 5 Changed 10 years ago by
Perhaps you could submit pull request for us? Preferably with tests.
comment:5 Changed 10 years ago by
Replying to orkel:
Perhaps you could submit pull request for us? Preferably with tests.
Sure, I'll do this.
comment:6 Changed 10 years ago by
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).
Do you have a use case where leaving these properties set to undefined on the window is an issue?