Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!