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

209
Visualizações
Why does the delete operator deletes a function constructor?

In this post, It says that the delete operator does not work on functions.

The invocation of the delete operator returns true when it emoves a property and false otherwise. it’s only effective on an object’s properties, it has no effect on variable or function names.

But consider this code:

delete Date;
new Date(); // thros an reference error

To make sure that Date is a function constructor, I wrote:

typeof Date; // "function"

This piece of code verifies that Date is a constructor, not an object. If the delete operator work on this particular type of function constructor, it should work on my constructor also. But it doesn't.

function a(){}
var b = new a();
delete a; // false

So, the delete operator did not delete my function constructor but for some reason, it deleted the Date constructor. Can someone clear this confusion of mine?

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

0

If you are doing this in a browser context then Date is a property on window, which is what you actually deleted. That the value of that property is a constructor/function doesn't really matter, the property is gone and most likely that was your only reference to that function.

This still works and returns a date object.

var dateFn = Date;
delete Date;
new dateFn();

Because it was only the property that was removed and not the actual function.

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