This is convenient for little scripts like unit tests, but it opens
the door for misuse. Libraries shouldn't ever use it since it will
pollute the global namespace.
CommonJS does not have such a method and consequentially necessitates
lots of boilerplate code like this:
var blah = require("blah");
var foo = blah.foo;
var bar = blah.bar;
I want to avoid this, but include() (at least in its present form) is
not the right way to solve it.
I will remove it. Unless there are some strong objections?
I like it!
node.extend(process, require("/file.js"))
instead of
include("/file.js");
It's more verbose but leads to better namespacing. It reads okay too.
This would also address Isaac's problem:
http://groups.google.com/group/nodejs/browse_thread/thread/187afe17c698578c
node.mixin() with the same semantics as jQuery.extend() except if the
first argument is left out, then it uses "process".
E.G.:
node.mixin(require("/file.js")); /* was: include("/file.js"); */
/* Isaac's use case */
node.mixin(exports, require("/file.js"), require("/mjsunit.js"));
I'm against it. This is something that can be done in user code - I
think node would be overstepping it's scope if it did that. Even
require() is a bit out of the scope of node - which I'd like to only
focus on I/O - but is a necessity.
I really like using include because it lets me avoid writing a ton of
lines to essentially "consider this other code file part of the
current one". To be honest, I don't think there are many use cases
for merging things with 'process' that wouldn't be as well or better
served by a 'put everything here in the current scope' tool.
Cheers,
Jacob
As far as I can see, it's not possible to create a function which
takes one object and merges it into the local scope.
node.mixin(require("/file.js"));
Not any good ways at least. I found a similar solution when playing
with my turtle.js meta-programming example, but it required some nasty
hacks that have to be done at the text level. So some function in
node would wrap the source code to a file in a with statement (with
the passed in object as the "with" scope) and then eval/execute it.
It would be nice to drop that weight. However, I find it would be a
terrible burden to load a module system at the beginning of each
script. (I suppose someone could wrap Node with a different script...
hmm. That might be something to try.)
> Actually, I'm almost of the mind that node.js should just get it over with
> and start using the commonjs module system... it has some slightly different
> syntax, but its basically the same thing. I'm not exactly sure what the
> reasoning is for avoiding it.
Yeah. I'm just not sold on their interface. I guess if people bother
me enough I'll adopt it.
What if I provided a "node-core" executable which would provide all of
the C++ stuff, node.dlopen, node.fs.*, the event loop, etc but without
the module system. Basically leaving out src/*.js. Would you find this
useful to provide your own module system?