Hacker News new | past | comments | ask | show | jobs | submit login

> We've added file-level JavaScript variable scoping. Variables declared with `var` at the outermost level of a JavaScript source file are now private to that file. Remove the `var` to share a value between files.

I think it is convenient to be able to declare global variables like that but perhaps there should be a way to monitor those ; in other words, it would be really convenient to have some form of alert system to notify you when a new global variable is created.

That way, globals created by mistakenly forgetting the 'var' keyword would be easily spotted.




This is under active development on the linker branch: https://github.com/meteor/meteor/tree/linker ! The goal, hopefully coming in one of the next few releases, is to provide package-scoped variables and explicit exports from packages, so that you don't need to rely on globals at all any more.


I'm happy to hear this. One of the primary problems with client-side development right now is the lack of commonjs style imports and exports -- something which people are trying to solve using component, etc. It'd be nice if Meteor had something baked in.


Seems like a good idea to add outside of meteor projects too. Maybe an extension for Chrome dev tools that lists global variables loaded per page?


This will give you a list of globals in browser

for(var i in window){ if(typeof window[i]=="object"){console.log(i);} }

But I think op wanted variables server side as well


I think it would be good to have that on both the client and the server.

Also, as simple as this might be, making it a de-facto standard (on meteor) would be a good thing since it would be a tool that we can count on, all the time. There are too many browsers IMO to make an extension a viable option.

Whitelisting variables would be good as well ; that way we do not get alerted if it is something we expect to be global.


Create a collection called MyVars and add this to your Server.js file:

Meteor.setInterval(function(){ for(var i in global){ if(MyVars.find({name:i}).count()==0){ MyVars.insert({name:i}); console.log("New Public Variable: ", i); } } }, 5000);

Thanks for the fun challenge :-)


Alert system if you're running Canary with experimental JS flag on:

Object.observe(window, function(changes){ console.log(changes) })

:)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: