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

244
Visualizações
how to generate a static function without 'class{}'?

how do I generate something like:

function generator() {
static funct(){}
}

I think I'm wrong, but from what I understand the class {} method is built on top of function(){}, so it should have the same method. The point is that static methods don't have a .prototype, and I'd like to know how they're created via class {}

@UPDATE
apparently from what I understand the class {} method actually builds static functions through Object(), since both can create static functions.

class A {
  static a() {}
}

const B = {b(){}};

console.log('a' in A && 'b' in B)
console.log(`${A.a.prototype}, ${B.b.prototype}`);

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

0

Honestly, the closest you can get is just removing it yourself:

function generator() {
  if (!(this instanceof TestClass)) throw new TypeError("Cannot call a class as a function");
}

generator.funct = function() {
  console.log(this.funct);  
  return "test";
}

generator.funct.prototype = undefined;

console.log(generator.funct())
console.log(generator.funct.prototoype)

gives the same output as

class generator {
  static funct() {
    console.log(this.funct)
    return "test";
  }
}

console.log(generator.funct())
console.log(generator.funct.prototoype)


But I don't see why this is necessary, even in Babel when transpiling into ES5 syntax, static methods still have prototypes.

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