deitch
unread,Sep 20, 2011, 10:25:08 AM9/20/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nodejs
I am looking for some way to require() (or otherwise load) files that
do not conform to the module structure. This is primarily useful when
using 3rd-party client-side libraries that do not have a module
structure, but has other uses as well.
When I do require(), it loads the file with module (and hence
module.exports = {}), and module.exports is returned to the require()
call.
It would be useful if I could find some way to require() an arbitrary
file, pass it any number of arbitrary vars, and then take those vars
as well as "this" from inside the file/pseudomodule.
E.g. if require() had an options array, I could do:
specialVar = {};
foo = require('./somefile.js',{specialVar: specialVar});
Inside the file, it expects specialVar (e.g. window, if it is a client-
side lib) to be available, populates it, even gives a context to
"this". I can then see what specialVar is set to be the library, or
even look at foo.specialVar or foo._this (special variable that
references "this" inside the file) to extract data that I need.
This allows me to have a fully functioning module that does not
conform to the node modules standard, provided I call it with the
correct environment.
Thoughts? Is there any way to do this now?