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

233
Visualizações
How to instantiate a <code></code> element in JavaScript (NodeJS)?

The HTMLPreElement type in JavaScript produces a DOM element corresponding to the <pre> tag. Where is the type corresponding to <code>? It seems there should be an HTMLCodeElement type, but there isn't. How do I go about instantiating this in NodeJS JavaScript?

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

0

const c0d3 = document.createElement("code");
Object.getPrototypeOf(c0d3).constructor.toString();
//function(){return a.Reflect.construct(a.HTMLElement,[],this.constructor)}

At least on the browser side (Chrome, on node side you possibly have other workarounds to create mock DOM elements), it is not directly a distinct constructor, but rather a wrapper function that makes use of HTMLElement itself and another function this.constructor that is passed as an argument to Reflect.construct.

The old way of creating these native constructors are generally something like:

//Instances inherit from parent proto
HTMLSomeChildElementFunc.prototype = Object.create(HTMLSomeParentElementFunc.prototype);

//Statics are inherited on the constructor
Object.setPrototypeOf(HTMLSomeCHildElement, HTMLSomeParentElement);

In this case it is a bit different, they went for some sort of monkey patch.

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