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

241
Visualizações
Is there a way to programmatically determine that a function is actually an object in Javascript?

In Javascript, functions are objects. Yet typeof of a function returns function instead of object for ECMAScript compatibility reasons.

Is this function type actually some kind of wrapper for object that can be determined somehow? Or in Javascript, is a function actually fundamentally different from objects?

I do understand that functions are effectively and practically objects. But are they by definition actually completely separate from Objects in Javascript, or is there a way to programmatically reveal the Object that the Function is made of?

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

0

As the spec says:

an object is a member of the built-in type Object; and a function is a callable object

So

Or in Javascript, is a function actually fundamentally different from objects?

Not really, except for the fact that a function is callable - more precisely, that it has a [[Call]] internal method.

Functions inherit from objects in a very similar way that objects inherit from objects. For example, for a given function:

function foo(){}
foo.a = 'a';

There is:

  • The foo function, which is an object, and has a [[Call]] internal method, as well as an a property, and a few other properties that functions have (like name)
  • The foo function inherits from Function.prototype
  • Function.prototype inherits from Object.prototype
  • Object.prototype inherits from nothing - that's the start of the prototype chain

is there a way to programmatically reveal the Object that the Function is made of?

That's not really how it is - the function itself is an object. If the function object has properties, it'll be visible directly on the function. For example, above, referencing foo.a will give you the string 'a'. The a property isn't separate from the function - it's directly on the function object.

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