I'm currently using an globals object to store variables used by other objects.
globals.js
export default {
colors: {
bg: 0x000000,
front: 0xffffff
},
scene: new THREE.scene();
};
which allow me to do this in a given class:
Foo.js
import globals from './globals.js';
class Foo {
constructor() {
this.color = globals.colors.front;
// ...
globals.scene.add(this.mesh);
}
}
I'm wondering if this is a good way to work. Should I create a separate module for each object (say a colors.js file and a Scene.js) and import them wherever needed? Or is a globals object fine? I can't think of any drawbacks but it doesn't seem clean to me.