The following JavaScript code will work in both Safari and Chrome, but with different results.
I would like to know why this is happening.
<script>
class Bar {
'use strict';
baz() {
return new Promise((resolve) => {
resolve();
}).then(() => {
return [2];
});
}
}
new class {
'use strict';
#foo = 1;
constructor() {
console.log(this.#foo); // 1
(new Bar()).baz()
.then((res) => {
console.log(res); // [2]
console.log(this.#foo); // 1
[this.#foo] = res;
console.log(this.#foo); //*** Chrome: 2, Safari: 1 ***
});
}
}
</script>
Note that if you declare #foo as foo instead of private static methods, the final result will be 2 for both.
Chrome 97.0.4692.99
Safari 15.3 (17612.4.9.1.5)
macOS Monterey Ver. 12.2
MacBook Air (M1,2020)