-
Notifications
You must be signed in to change notification settings - Fork 20.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove window object references and fix whitespace #3417
Conversation
Always declare global variables. https://gist.github.com/david-mark/7cf93afccf3696a4f6754b36cd6ab34e
@david-mark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @timmywil, @dmethvin and @mgol to be potential reviewers. |
Integration tests indicate that some other file needs a variable name change. Certainly "jQueryDefined" is defined in the file I changed. Also added it to "globals" in the lint JSON, which makes little sense to me as it isn't a global at all (nor is "noGlobal", which is also in there). Leave that to you. Not sure what that "global.js" file is supposed to do (could use some more comments), but there's no good reason for it doing it the way it was. Edit: I get it. It's strictly a NodeJS script. Had mistaken that one for some sort of AMD-like wrapper. Edit: Quite the paradox: this "global.js" script is run in NodeJS and painted into a corner by the local "jQuery" argument. In NodeJS, could use "global" instead of "this", but the function is clearly not meant for NodeJS as it uses "window" to try to reference the global object. There's only one quick way to fix this and that's to remove 'use strict'; unfortunately, that causes the integration test to fail for that file. /home/travis/build/jquery/jquery/src/exports/global.js Good luck with all that. Whatever you do, stop substituting the - window - host object for the global object. And ideally, declare all of your globals. |
Thank you for your contribution. However, we'd like to keep this the way it is. It has seen many revisions to get to this point (and has withstood the test of time). I see no practical reason to change it, just a blanketing ideological argument. Notice that the |
Nothing ideological about the fact that host objects are not part of the language. Relying on them for no reason leads to confusion and cross-platform issues. The fact that the code seems to "work" is no reason to close this ticket and ignore the underlying confusion that likely led to the "many revisions". ;) There is a very practical lesson to be learned here if you are willing to consider what led you to this point. Understanding the previous missteps surely trumps the "test of time". Just because it has somehow "worked" over an unspecified period of time does not mean there is nothing to be gained through understanding and correcting past mistakes.
That has nothing to do with my changes (though you likely need to make similar changes elsewhere to completely untangle this mess). You are simply confusing the
Also has nothing to do with it. Did nothing to prevent the use of var global = global || this; This has (or should have) nothing to do with Good luck! :) |
@david-mark Take another look at src/wrapper.js , and at uses of |
I already saw it and just adjusted a line in my fork to support NodeJS, where the global object is named "global". As mentioned we were missing that bit as well. One more problem solved, but it had nothing to do with the rest of your post or the previous cite related to this file.
You are indeed confused. You reference the global And yes, the If you want to explicitly pass the global window object to your factory (which would make sense, but would not make a bit of difference in browsers), then do just that. Instead of checking for In any event, it made no sense to pass As for whatever object gets passed to your factory when running in NodeJS, I can't see how that has anything to do with any of my changes, certainly not those to the wrapper.js file. Per the comments, this is the pertinent part of the code: // For CommonJS and CommonJS-like environments where a proper `window`
// is present, execute the factory and get jQuery.
// For environments that do not have a `window` with a `document`
// (such as Node.js), expose a factory as module.exports.
// This accentuates the need for the creation of a real `window`.
// e.g. var jQuery = require("jquery")(window);
// See ticket #14549 for more info.
module.exports = global.document ?
factory( global, true ) :
function( w ) {
if ( !w.document ) {
throw new Error( "jQuery requires a window with a document" );
}
return factory( w );
}; And the previously cited line that throws the exception is inside your exports function. Haven't made any changes that affect that as it has its own So what are you trying to say? Which line do you think will fail here and how do you figure my proposed changes will make it fail. Suggest removing the strict mode check from this file, allowing the integration tests to finish and then trying out the changes. Will likely save time. Finally, this is just one change among several. There was at least one other place where Best of luck! :) PS. You really shouldn't use |
Here is the latest pull request (now closed due to above confusion). ...As mentioned, the last change may not even be necessary, but certainly makes sense for NodeJS in case there is a way to provide global |
No, we reference the local
To repeat myself, "complete with properties like
Previously cited? Did I miss something?
The current code prioritizes
|
I had just edited my comment to make that more clear, but it's still a reference to the global window object, at least in browsers. I changed it to a reference to the global object in all environments, whereas you were passing
Repeating it doesn't make it any more lucid. Re-read what I posted, particularly after the last edit. You do realize that both
Apparently. Cited by "timmywil" above.
There's just no need to prioritize anything. Re-read the suggestions I made in the last edit. In short, you start by passing a reference to the global object (as an argument that has always been called "global"). From there you can find both
This is another misunderstanding. You should not be adding How can there be an issue reference is there is no known bug? This is just about untangling a mess and making the code that much easier to follow. And unit tests will be relevant once the integration tests are adjusted to allow the removal of the useless Again, good luck to you! |
New pull request: Read carefully before closing and perhaps you won't close this one. I agree that there was some fine-tuning required to be perfect. Hadn't claimed perfection in the first place, but insist that the end result of my efforts is much clearer code. Will add some comments next to be perfectly clear about what it is doing and why. |
Summary
Checklist
Mark an
[x]
for completed items, if you're not sure leave them unchecked and we can assist.Thanks! Bots and humans will be around shortly to check it out.
Always declare global variables.
https://gist.github.com/david-mark/7cf93afccf3696a4f6754b36cd6ab34e