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

226
Visualizações
difference between constructor and class in javascript

what is the const halley=... referring to?Is it storing the new created object?or is itself a new object?and what does the Dog after the new keyword means?Class or constructor?

class Dog {
 constructor(name) {
   this.name = name;
   this.behavior = 0;
 } 
}

const halley = new Dog('Halley'); // Create new Dog instance
console.log(halley.name);
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

In JavaScript, a constructor function is a function designed for use with the new keyword to create instances of a type of object. Typically you would assign something to its prototype property to define properties that would be inherited by the instance.

The class keyword is a newish feature that allows the creation of a constructor function and its associated prototype using syntax which looks more like traditional OO syntax in other programming languages.

The value assigned to Dog is both a class and a constructor function.

about 4 years ago · Juan Pablo Isaza Relatório

0

This part define the class. A class is like a recipe to make objects. A constructor is a method of a class that define how to create new instances (objects):

class Dog {
 constructor(name) {
   this.name = name;
   this.behavior = 0;
 } 
}

This part create an instance (object) of the class Dog:

const halley = new Dog('Halley');
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