In the example below, it should print out false the first time, but it should be changed to true after that. But it stays the value it was originally assigned.
var i = {
control: {
a: false,
b: false,
}
}
var test = i.control['a'];
setInterval(function () {
document.body.innerHTML += test + ', ';
i.control['a'] = true;
}, 500);
I want to be able to update the variable externally, but the loop needs to be able to check what the variable is set to (which could be any of the values in that object, and will be set on initialization).
I am doing this to try to keep the code clean, and without having to create a new variable each loop to get/store the latest value.
You could take the object reference and take the last key for the value.
var i = { control: { a: false, b: false } },
test = i.control;
setInterval(function () {
document.body.innerHTML += test.a + ', ';
i.control.a = true;
}, 500);
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