I've thrown a lot of tracking points, and still can't understand the output.
Version 1
Script (firefox 99.01 Windows):
<html>
<head></head>
<body></body>
<script type="text/javascript">
console.log("======= Ready state = " + document. readyState);
initiate_timed_updates();
function initiate_timed_updates() {
var timed_items, i;
console.log("Test point 1:");
console.log(timed_items);
try {
console.log(timed_items[0].trigger_time.toString());
} catch(e) {
// expected to fail, undefined
}
timed_items = [
{ trigger_time: "17 April 2022 00:20:00", new_settings: [], data: 5, text_info: "test_string" }
];
console.log("Test point 2");
console.log(timed_items);
console.log(timed_items[0].trigger_time.toString());
console.log("Test point 3");
for (i = 0; i < timed_items.length; i++) {
console.log("Setting a datetime...");
timed_items[i].trigger_time = new Date(new Date().getTime() + 1000 * (5 + 3 * i));
}
console.log("Test point 4");
console.log(timed_items);
console.log(timed_items[0].trigger_time.toString());
console.log("Test point 5");
}
</script>
</html>
Console output:
(Ive expanded the array at lines 6+11)
This page is in Quirks Mode. Page layout may be impacted. For Standards Mode use “<!DOCTYPE html>”. test9.html
======= Ready state = loading test9.html:6:11
Test point 1: test9.html:13:13
undefined test9.html:14:13
Test point 2 test9.html:25:13
Array [ {…} ] test9.html:26:13
0: Object { trigger_time: Date Sun Apr 17 2022 15:08:04 GMT+0100 (British Summer Time), data: 5, text_info: "test_string", … }
data: 5
new_settings: Array []
text_info: "test_string"
trigger_time: Date Sun Apr 17 2022 15:08:04 GMT+0100 (British Summer Time)
<prototype>: Object { … }
length: 1
<prototype>: Array []
17 April 2022 00:20:00 test9.html:27:13
Test point 3 test9.html:28:13
Setting a datetime... test9.html:31:15
Test point 4 test9.html:35:13
Array [ {…} ] test9.html:36:13
0: Object { trigger_time: Date Sun Apr 17 2022 15:08:04 GMT+0100 (British Summer Time), data: 5, text_info: "test_string", … }
data: 5
new_settings: Array []
text_info: "test_string"
trigger_time: Date Sun Apr 17 2022 15:08:04 GMT+0100 (British Summer Time)
<prototype>: Object { … }
length: 1
<prototype>: Array []
Sun Apr 17 2022 15:08:04 GMT+0100 (British Summer Time) test9.html:37:13
Test point 5 test9.html:38:13
Problem part 1:
What's happening at console lines 26:13 and 27:13?
From line 26:13:
0: Object { trigger_time: Date Sun Apr 17 2022 15:08:04 GMT+0100...
--> trigger_time: Date Sun Apr 17 2022 15:08:04 GMT+0100...
From line 27:13:
17 April 2022 00:20:00
26:13 correctly states that the value of trigger_time is a Date object, but why does it then give the current date as its value when it outputs the array, and then the correct value when output individually, at 27:13.
(It can't be because that's the default value of its object type, new Date(), because otherwise data (int), text_info (string) etc would show their defasult null values too.)
But then it gets wierder. Comment out the last part of the script, don't change the first part at all. Should make no difference to the earlier output....
Version 2 (last part comented out):
Script:
<html>
<head></head>
<body></body>
<script type="text/javascript">
console.log("======= Ready state = " + document. readyState);
initiate_timed_updates();
function initiate_timed_updates() {
var timed_items, i;
console.log("Test point 1:");
console.log(timed_items);
try {
console.log(timed_items[0].trigger_time.toString());
} catch(e) {
// expected to fail, undefined
}
timed_items = [
{ trigger_time: "17 April 2022 00:20:00", new_settings: [], data: 5, text_info: "test_string" }
];
console.log("Test point 2");
console.log(timed_items);
console.log(timed_items[0].trigger_time.toString());
console.log("Test point 3");
/*
for (i = 0; i < timed_items.length; i++) {
console.log("Setting a datetime...");
timed_items[i].trigger_time = new Date(new Date().getTime() + 1000 * (5 + 3 * i));
}
console.log("Test point 4");
console.log(timed_items);
console.log(timed_items[0].trigger_time.toString());
console.log("Test point 5");
*/
}
</script>
</html>
Console output:
This page is in Quirks Mode. Page layout may be impacted. For Standards Mode use “<!DOCTYPE html>”. test9.html
======= Ready state = loading test9.html:6:11
Test point 1: test9.html:13:13
undefined test9.html:14:13
Test point 2 test9.html:25:13
Array [ {…} ] test9.html:26:13
0: Object { trigger_time: "17 April 2022 00:20:00", data: 5, text_info: "test_string", … }
data: 5
new_settings: Array []
text_info: "test_string"
trigger_time: "17 April 2022 00:20:00"
<prototype>: Object { … }
length: 1
<prototype>: Array []
17 April 2022 00:20:00 test9.html:27:13
Test point 3 test9.html:28:13
Problem part 2:
Now the array output at 26:13 has changed.
True, it's now as expected, value is per code not object default value. But we didn't change any of the code that runs prior to the point that's output....?
From line 26:13:
0: Object { trigger_time: "17 April 2022 00:20:00", ...
--> trigger_time: "17 April 2022 00:20:00"
From line 27:13:
17 April 2022 00:20:00
Bug, or something subtle I'm missing?