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
Proposal: global.window = global #1043
Comments
-1 It seems like a bad idea to let people pollute the global namespace by default like that on the server side, especially if there is a dependency that pulls in such browser-side javascript module and the user is totally unaware that globals are being messed with. IMHO it's better to fix the javascript in question to detect node and set |
I'm -1. Seems like encouraging a bad habit. |
-1 It's not like this is browser-land where there isn't yet a module system in place. |
Adding |
-1 The |
-1 Ugly, potentially breaking and doesn't actually solve anything. |
-1 Terrible idea |
There are probably more problems with importing code that depends on Perhaps a simple mention of something like JSDOM is sufficient for people looking to run browser code in IO.js. |
So, this is clearly a bit unpopular so far! Nevertheless, some of the objections are substantive, so I will explain my reasoning. @mscdex You say "it's better to fix the javascript in question to detect node and set module.exports instead." And I don't disagree. But that is orthogonal to the problem. You can still modify the code to detect node and set module.exports, and there are other ways to detect the browser. But this would make much of that work optional, strictly increasing the utility gained from the corpus of JavaScript to date. @cjihrig What bad habit it would it be encouraging? People already can set things as globals in node. (Not to mention that every module is a global.) @Fishrock123 "It's not like this is browser-land where there isn't yet a module system in place." I don't see the relevance. @chrisdickinson Breaking existing node modules is a good point. I should try to see about investigating public npm packages for that behavior. @tellnes There are already lots of ways we directly tell users that. See also my response to @chrisdickinson. If this is the primary blocker, it can be quantified and investigated quite easily. @moll While yes, code that does |
If this lands in tree it'd probably be around forever. For that reason alone I feel time – and counter-arguments like above – needs to stand between opinion and commits. |
But they don't do that. CJS format as used in iojs, totally deprecates using globals. It may even be better if there's no Bringing iojs is different world, and it should not pretend it isn't, it'll be just confusing. It's much better if those not educated crash at first step. |
I guess ES6 module is the true key for removing friction for browser and server. If io.js team will support ES6 module, I am If io.js team will not support it, I am |
I am with @yosuke-furukawa here. The differences io.js and browser coding should be as minimal as possible and I think supporting ES6 modules should be the aim and would be preferred, but if that is not planned, 👍 for this proposal. |
-1 on It's a very modest proposal as |
@drkibitz That doesn’t make sense. In browsers, |
@mathiasbynens that's why I mentioned that in my comment if it were implemented as |
-1 on this. I saw too much code that attaches itself as a global if |
It seems the responses are overwhelmingly negative. Moving to close. @yosuke-furukawa Apropos ES6 modules, nothing has been hashed out yet but the plan is to support them eventually. There is still a lot of work to be done in V8 before io.js can start looking into it, though. |
We can make a suggestion for legacy usage that use a window module instead.
It's a pollyfill for window object that make compatible between iojs and On 2015年3月10日 周二 at 下午6:44 Ben Noordhuis notifications@github.com wrote:
|
@bnoordhuis |
There is no actual |
-1 We shouldn't embrace the bad parts of client-side JavaScript just to encourage jQuery plugin developers to publish more modules on npm |
-1 in core, +1 in user land. It seems that this could become a well-documented (and thus google-able) solution for folks to do before they |
-1 👎 have to echo @chrisdickinson's argument here. I'm also guilty of doing some On a related note: bringing some data to this argument by static analysis of |
-1 this needs to be solved by ecmascript. There should be a way to get the global object, then we can polyfill that in the browser and add it ti node. Think about web workers - window is not the global in that context. |
@isaacs I'm -1 for many obvious reasons, but as an idea, perhaps changing code here could "fix" references to NativeModule.wrapper = [
'(function (exports, require, module, __filename, __dirname, window) { ',
'\n});'
];
NativeModule.prototype.compile = function() {
var source = NativeModule.getSource(this.id);
source = NativeModule.wrap(source);
var fn = runInThisContext(source, { filename: this.filename });
fn(this.exports, NativeModule.require, this, this.filename, global);
this.loaded = true;
}; |
-1
ATM, there are literally no +1s in this thread (except a conditional +1 or 2). I'm not sure I've ever seen such consensus on a technical solution in an open source project before. I can't help but smile in agreement. Seems like a pretty strong signal. I'm in agreement with @bnoordhuis in favor of closing the issue. |
re: |
Browserify encourages the use of global, automatically sniffing, On Thursday, March 12, 2015, Zeke Sikelianos notifications@github.com
|
Points taken. Just so we're clear, yes of course I know that there are countless ways to work around this in userland code. I am not brand new to JavaScript. I've designed and written a few modules, and a few module systems, including this one. I do know how it works, but thank you all very much for all the educational pointers about node's module system, just in case I had forgotten. The point is that this would make a lot of currently-existing legacy code work without intervention in userland, so suggesting userland fixes isn't really relevant. I know it's not much intervention. |
Well… actually, +1 🎉 💃 |
Maybe non-client node developers are a minority, maybe not, but I have to say that browserisms in the node API stick out like a sore thumb (process.nextTick, global setTimeout... wtf?), and adding to that list doesn't excite me. That said, I do like minimizing pain... I just don't see "oh, node code works differently" as pain... obviously its different. and wouldn't doing
anywhere in user code make node be like the browser? Its even idempotent, you can do it over and over. |
@isaacs I would suggest that if Building isomorphic apps means that you explicitly want to go one direction or another depending on if you are in a browser or not... by defining a global window, that tends to break down that detection a bit. I've also written JS for other platforms outside of node and browser... I'd prefer to keep that consideration in mind. |
oh ... irony ... it's ending up even more badly when I've asked to stop this madness and bring |
One of the biggest and weirdest stumbling blocks I'm seeing as people try to use npm and CommonJS for browser code is the difference in spelling of
global
vswindow
.I'd like to propose that we just go ahead and create a global called
window
that is a reference to node'sglobal
object.Yes, yes, "window" is a silly name. It was silly in the browser, and it's even sillier outside of it. But it's a fixture in the language, extremely low-risk, and will reduce a lot of friction onboarding browser JavaScript people.
The text was updated successfully, but these errors were encountered: