You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be really nice if there was a simple "include" function to include a js file in a page. Of course there are modules, but sometimes it is nice to be able to include another file for any reason. Currently this can be done in a roundabout way:
function include(f) {
eval.apply(global, [fs.readFileSync(f).toString()]);
}
But this has serious limitations. Using eval makes debugging very difficult. You can't tell which file the error message is coming from. Adding a simple "include" ability for a raw js script would make things much easier.
This addition would significantly increase the flexibility that io.js provides, making it an even more useful tool. My guess is that such an include is considered "bad practice" in node. But let's be honest... Javascript is by nature a flexible language - dynamically typed, contains eval, all the things that stiff programmers hate. It's the nature of the language, and keeping it out doesn't seem to be at the heart of js.
The text was updated successfully, but these errors were encountered:
Well, the problem is that require doesn't put things in the global scope. Right now I'm working on a smallish project, but just want to move some utility functions into a separate file. I could always just make a module u for utilities, but it just seems like is a legitimate use-case scenario for a requireGlobal function that includes the requires in the global scope.
Hello,
It would be really nice if there was a simple "include" function to include a js file in a page. Of course there are modules, but sometimes it is nice to be able to include another file for any reason. Currently this can be done in a roundabout way:
function include(f) {
eval.apply(global, [fs.readFileSync(f).toString()]);
}
But this has serious limitations. Using eval makes debugging very difficult. You can't tell which file the error message is coming from. Adding a simple "include" ability for a raw js script would make things much easier.
This addition would significantly increase the flexibility that io.js provides, making it an even more useful tool. My guess is that such an include is considered "bad practice" in node. But let's be honest... Javascript is by nature a flexible language - dynamically typed, contains eval, all the things that stiff programmers hate. It's the nature of the language, and keeping it out doesn't seem to be at the heart of js.
The text was updated successfully, but these errors were encountered: