I have a variable let activeNode;
in main.js
. It can be changed by either keyboard input or mouse input. The functions dealing with each are modularized into their own files keyboard.js
and mouse.js
. activeNode is exported into these modules.
Whenever the functions attempt to reassign the imported variable activeNode
, console logs the error Uncaught TypeError: Assignment to constant variable.
I've seen other answers saying to also create and export a function updateVariable(var)
in main.js
and then call it in the modules to reassign activeNode
, but I'd prefer not having to create an export and entire function just to reassign a variable.
Is there any other way to accomplish cross-module reassignment of variables? (And without having to pass the variable into the module function calls, because the mouse input function calls are deeply nested in main.js and I don't want to have to tunnel a parameter through a bunch of higher level functions.)
Aucun commentaire:
Enregistrer un commentaire