Specifically I'm testing this in the latest version of Google Chrome, but I suspected this would be the same in Edge/Firefox/Safari (Last I was aware Edge and Firefox had modules hidden in experimental javascript flags)
In a 'globals.js' I have a let scale.
// inside global.js
let scale = 1;
In another module, I wanted to adjust the scale
// inside another js file
import { scale } from "../JS/globals.js";
scale = Math.min( scale + ((scale + delta) * speed), target);
But I'm getting error "Assignment to constant variable".
I imagined one obvious way to do this, is to export a function named set_scale
// back in globals.js
export function set_scale (value) { scale = value };
And I have already done this for a few other variables from globals.js. But I wanted to know if anyone has any other methods for overcoming exports/importing lets as constants, especially if it will allow me to avoid making more things to export/import.
You can do as following in your globals.js file:
export default {scale: 1}
and in the other modules, use it like this:
import global from "global"
global.scale = ...
... = global.scale
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With