以下JavaScript代码可以在Safari和Chrome中运行,但结果不同.
我想知道为什么会发生这种情况.
<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>
请注意,如果将#foo声明为foo而不是私有静电方法,那么两个方法的最终结果都将是2.
chromium 97.0.4692.99
afterwards:
I heard that it will be fixed in the next version.
https://webkit.org/blog/12193/release-notes-for-safari-technology-preview-139/