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

109
Visualizações
Terser setting to minify/hoist the this variable and properties

Is there any way for terser to minify/hoist the this variable so it does not appear repeated as often in the bundle?

Example code:

class MyClass {
    constructor(handler) {
        this.handler = handler;

        this.handler.on('method1', this.method1.bind(this));
        this.handler.on('method2', this.method2.bind(this));
        this.handler.on('method3', this.method3.bind(this));
        this.handler.on('method4', this.method4.bind(this));
        this.handler.on('method5', this.method5.bind(this));
        this.handler.on('method6', this.method6.bind(this));
        this.handler.on('method7', this.method7.bind(this));
        this.handler.on('method8', this.method8.bind(this));
        this.handler.on('method9', this.method9.bind(this));
        this.handler.on('method10', this.method10.bind(this));
    }

    method1() {}
    method2() {}
    method3() {}
    method4() {}
    method5() {}
    method6() {}
    method7() {}
    method8() {}
    method9() {}
    method10() {}
}

new MyClass();

Ideally, I would love terser to be smart to detect repeated usages of this and hoist the reference. Something like this:

const a = this;
a.handler.on('method1', a.method1.bind(a));
// ...

What about the handler property? Perhaps it can be also smart and compress further to:

const a = this;
const h = a.handler; // (actually, `handler` because it's argument var)
h.on('method1', a.method1.bind(a));
// ...
about 4 years ago · Juan Pablo Isaza
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