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

312
Visualizações
TypeError: Person.greet is not a function

function Person(name, age, greet) { 
  this.name = 'Josh';
  this.age = 15;
  this.greet = function(greeting) {
   console.log('Hello I am ', this.name)
  }
}

Person.greet();

I'm trying to get the console to show "Hello I am Josh", I get the same error saying Person.greet is not a function

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

0

function Person(name, age, greet) { 
  this.name = name;
  this.age = age;
  this.greet = function(greeting) {
   console.log('Hello I am', this.name)
  }
}

const max = new Person();
max.name = 'max';
max.age = 18;
max.greet(); // Hello I am max

I realised that I was using a factory function, I was meant to create an object using the new keyword

about 4 years ago · Juan Pablo Isaza Relatório

0

This seems to be a constructor function, and not an object, hence, you need to call new to create instance of the constructor function before invoking the methods.

// on a side note, if you're not going to use the arguments, better remove them altogether
function Person(name, age, greet) { 
  this.name = 'Josh';
  this.age = 15;
  this.greet = function(greeting) {
   console.log('Hello I am ', this.name)
  }
}

const person = new Person();
person.greet();

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