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

234
Visualizações
Some error on constructor and recursion i don't seem to understand

I'm working on constructor, at first I was using ES5 and my error was "Message is not a function" then I saw something about arrow function not been used with constructor so I removed it and got another error saying "Maximum call stack size exceeded" something about recursion. I don't know what exactly I'm doing wrong. have seen a lot of answers on constructor but none of them seems helpful.

function Message(name, motive, hubby){
 this.name = name
 this.motive  = motive
 this.hubby = hubby
 this.output=function(){
return `Hi, i'm ${this.name} i love ${this.hubby} and i would love to be your ${this.motive}.`
}
 var Mymessage = new Message('josephine','friend', 'coding');
 console.log(Mymessage.output()); 
}
 Message();
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

This is how you should create an instance and call a function of that instance

function Message(name, motive, hubby){
     this.name = name
     this.motive  = motive
     this.hubby = hubby
     this.output=function(){
    return `Hi, i'm ${this.name} i love ${this.hubby} and i would love to be your ${this.motive}.`
    }
}
var Mymessage = new Message('josephine','friend', 'coding');
console.log(Mymessage.output()); 
about 4 years ago · Juan Pablo Isaza Relatório

0

function Message(name, motive, hubby){
 this.name = name
 this.motive  = motive
 this.hubby = hubby
 this.output=function(){
  return `Hi, i'm ${this.name} i love ${this.hubby} and i would love to be your ${this.motive}.`
  }
}
 var Mymessage = new Message('josephine','friend', 'coding');
 console.log(Mymessage.output()); 
 Message();

You must write var Mymessage outside the Message function , as you have called it inside the same function, that line of code is calling itself again and again which is causing an erro .

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