Lets say I have one variable var car = 'VW'
in index.html
index.html
is the binding of my application, from there I access several modules:
<script>
var car = 'VW';
var Initializer = require('./js/initializer');
Initializer.check_requirements();
</script>
Now in initializer
I try to access this variable what does not work.
var Initializer = {
check_requirements: function(){console.log(car)};
};
module.exports = Initializer;
However when I attach the variable car
to window
:
window.car = 'VW';
Then Im able to access it in my module over window.car
;
How do I create an global variable car
that I can also access in my modules, so that I do not have to attach to window
?
Thanks