Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

223
Vistas
Accessing arguments from a class passed down from the constructor into a method using rest

I am trying to pass each argument through the constructor into the method which in turn encrypt the values. But, the Method isn't reading the values in the arguments.

Please, what am I doing wrong?

class Add {
    constructor(...words) {
        this.words = words;

    }

print(words){
    words = [words];
    let output = "$"
console.log(words)
    for(let word of words){
        output += word +"$"
    }
return output
}

    
}

var x = new Add("I", "Love","you");
var y = new Add("this", "is", "awesome");

x.print()
z.print()

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You misspelled constructor and also if you assign something to this inside of constructor then you can also access that on this in other methods.

class Add {
  constructor(...words) {
    this.words = words;
  }

  print() {
    let output = "$"
    for (let word of this.words) {
      output += word + "$"
    }
    return output
  }
}

var x = new Add("I", "Love", "you");
console.log(x.print())

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda