I have variables in app.js
:
var G = {};
module.exports = G;
var DATA = G.DATA = 'DATA';
var F1 = G.F1 = function(val)
{
return val;
};
In this way, I can export variables under the object G
, and at the same time, I can access the variable directly write DATA
without G
. prefix.
Now, I want to test for app.js
on test.js
var G = require('./app.js');
console.log(G.DATA); // -> DATA
This works, but I also want to access the variable by directly typing DATA
without G
. Prefix as console.log(DATA); // -> DATA
Certainly, I could do like:
var DATA = G.DATA;
For each variables (property) export and required module G
object, but obviously it is a tedious process to add each variable to the test file manually to match the% object_co_de%. >
Is there any way to do this automatically?
So far, I've been pessimistic since
JS G
closes function
in the scope itself, so in theory there is no way to have an auxiliary function for var
for each property object.
I'd like to avoid any var
or eval
solution node. I've tried them in the past, and had a lot of problems.