Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
Differences in behavior between Chrome and Safari for ES2022 private static methods

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)

afterwards:
I heard that it will be fixed in the next version.
https://webkit.org/blog/12193/release-notes-for-safari-technology-preview-139/

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I was able to reproduce the described behavior and to reduce the code to this:

(() => new class {
    #foo = 1;
    constructor() {
        [this.#foo] = [2];
        console.log(this.#foo); //*** Chrome: 2, Safari: 1 ***
    }
})();

This looks pretty much like a bug in JavaScriptCore/Safari.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda