I would like to do something like having cyclic dependencies. In order to do that, I have to resort to something like this:
// x.js
let y
exports.setY = function(_y) {
y = _y
}
// y.js
const x = require('./x')
x.setY(exports)
This sort of cyclic dependency problem happens all the time in database models, this referencing that, that referencing this. Ignore any ideas you might have on whether or not this specific use case of cyclic dependencies is a good idea, I'm more wondering if there is a way to convert a variable to a const in JavaScript after it has been declared. As in the let y
, after it is set, set it to a const.
Is anything like this possible? I would like to do this to get performance benefits as the key thing, I don't care about compile time checking benefits in this situation. Is there a way to make these two variables be compiled so they are maximally efficient?