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

135
Visualizações
JSDoc document final method

Is there a way to document a final method in JS using JSDoc.

A final method in Java is one which can't be overridden.

I couldn't find any option in JSDoc website.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It would seem you can't, since a search of the JSDoc documentaton for final turns up no results.

This isn't all that surprising, because you can't reliably have a final method in JavaScript. So if it's important for a method not to be overridden, you'll probably have to resort to documenting that in its description. Still, it would be possible for JSDoc to provide a way to annotate that for tools to pick up on, it just doesn't seem to have it.

Here's an unreliable way to have a final method in JavaScript:

class Base {
    constructor() {
        if (this.finalMethod !== Base.prototype.finalMethod) {
            throw new Error(`You must not override 'finalMethod' in your subclass.`);
        }
    }
    
    finalMethod() {
        console.log("This is the pseudo-final method");
    }
}

class Derived extends Base {
    finalMethod() {
        console.log("This is the overridden method");
    }
}

const d = new Derived(); // Throws error

But that's easily overcome in any of several ways:

  • Wait to create the method until your subclass constructor has already called the superclass constructor.
  • Return an object created without using the superclass constructor (for instance, return Object.assign(Object.create(this), { finalMethod() { /*...*/ } }); (Although now I think of it, that's really just a different way to do #1 above.)
  • Return a proxy.
  • Create your subclass instances without ever calling the superclass constructor (not recommended — but then, none of these are)
  • ...probably others...
about 4 years ago · Juan Pablo Isaza 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